Skip to content

Instantly share code, notes, and snippets.

View setaou's full-sized avatar
🙃

Hervé BRY setaou

🙃
View GitHub Profile
@setaou
setaou / json.py
Last active January 6, 2021 15:12
Custom JSON encoder/decoder that handles datetime.datetime (de)serialisation
# -*- coding: utf-8 -*-
import json
import datetime
import dateutil.parser
import re
iso_datetime_regex = re.compile(r"^(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z)?)|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z)?)|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z)?)$")
def new_scanstring(s, end, encoding=None, strict=True):