mirror of
https://github.com/netzbegruenung/green-spider.git
synced 2024-04-28 07:14:51 +02:00
Fix full JSON export
This commit is contained in:
parent
9e5426ccde
commit
ab942ca91d
|
@ -2,15 +2,27 @@
|
||||||
Exports data from the database to JSON files for use in a static webapp
|
Exports data from the database to JSON files for use in a static webapp
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from hashlib import md5
|
import datetime
|
||||||
import json
|
|
||||||
import logging
|
import logging
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
|
from hashlib import md5
|
||||||
|
|
||||||
|
import json
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
|
||||||
|
class DateTimeEncoder(json.JSONEncoder):
|
||||||
|
def default(self, obj):
|
||||||
|
if isinstance(obj, datetime.datetime):
|
||||||
|
return obj.isoformat()
|
||||||
|
elif isinstance(obj, datetime.date):
|
||||||
|
return obj.isoformat()
|
||||||
|
elif isinstance(obj, datetime.timedelta):
|
||||||
|
return (datetime.datetime.min + obj).time().isoformat()
|
||||||
|
else:
|
||||||
|
return super(DateTimeEncoder, self).default(obj)
|
||||||
|
|
||||||
def export_results(client, entity_kind):
|
def export_results(client, entity_kind):
|
||||||
"""
|
"""
|
||||||
Export of the main results data
|
Export of the main results data
|
||||||
|
@ -31,6 +43,6 @@ def export_results(client, entity_kind):
|
||||||
'score': entity.get('score'),
|
'score': entity.get('score'),
|
||||||
})
|
})
|
||||||
|
|
||||||
output_filename = "spider_result.json"
|
output_filename = "/json-export/spider_result.json"
|
||||||
with open(output_filename, 'w', encoding="utf8") as jsonfile:
|
with open(output_filename, 'w', encoding="utf8") as jsonfile:
|
||||||
json.dump(out, jsonfile, indent=2, sort_keys=True, ensure_ascii=False)
|
json.dump(out, jsonfile, indent=2, sort_keys=True, ensure_ascii=False, cls=DateTimeEncoder)
|
||||||
|
|
Loading…
Reference in a new issue