mirror of
https://github.com/netzbegruenung/green-spider.git
synced 2024-05-11 13:06:08 +02:00
c03ff21a9c
* Simplify exports * Create file output in current working directory
37 lines
995 B
Python
37 lines
995 B
Python
"""
|
|
Exports data from the database to JSON files for use in a static webapp
|
|
"""
|
|
|
|
from hashlib import md5
|
|
import json
|
|
import logging
|
|
import sys
|
|
import os
|
|
|
|
import requests
|
|
|
|
|
|
def export_results(client, entity_kind):
|
|
"""
|
|
Export of the main results data
|
|
"""
|
|
out = []
|
|
|
|
# Load data from database
|
|
query = client.query(kind=entity_kind)
|
|
for entity in query.fetch():
|
|
logging.debug(entity.key.name)
|
|
out.append({
|
|
'input_url': entity.key.name,
|
|
'resulting_urls': entity.get('checks').get('url_canonicalization'),
|
|
'created': entity.get('created').isoformat(),
|
|
'meta': entity.get('meta'),
|
|
'checks': entity.get('checks'),
|
|
'rating': entity.get('rating'),
|
|
'score': entity.get('score'),
|
|
})
|
|
|
|
output_filename = "spider_result.json"
|
|
with open(output_filename, 'w', encoding="utf8") as jsonfile:
|
|
json.dump(out, jsonfile, indent=2, sort_keys=True, ensure_ascii=False)
|