add type json

This commit is contained in:
j 2023-02-03 16:28:05 +01:00
parent 5919345d3d
commit e1657994ca

View file

@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
# vi:si:et:sw=4:sts=4:ts=4
import re
import json
from multiprocessing.pool import ThreadPool
from six import string_types
@ -77,6 +78,10 @@ class SiteParser(dict):
elif self.regex[key]['type'] == 'date':
parse_date = lambda d: d and datetime.strptime('-'.join(d), '%m-%d-%Y').strftime('%Y-%m-%d')
data = apply_f(parse_date, data)
elif self.regex[key]['type'] == 'json':
if isinstance(data, list) and len(data) == 1:
data = data[0]
data = json.loads(data)
if data:
self[key] = data