core: more generic functions to jsonify data, rescuetime: fix influxdb filling

This commit is contained in:
Dima Gerasimov 2021-02-13 19:28:32 +00:00 committed by karlicoss
parent 07f901e1e5
commit 4012f9b7c2
5 changed files with 65 additions and 32 deletions

View file

@ -143,6 +143,19 @@ def extract_error_datetime(e: Exception) -> Optional[datetime]:
return None
import traceback
from .common import Json
def error_to_json(e: Exception, *, dt_col: str='dt', tz=None) -> Json:
edt = extract_error_datetime(e)
if edt is not None and edt.tzinfo is None and tz is not None:
edt = edt.replace(tzinfo=tz)
estr = ''.join(traceback.format_exception(Exception, e, e.__traceback__))
return {
'error': estr,
dt_col : edt,
}
def test_datetime_errors() -> None:
import pytz
dt_notz = datetime.now()