Last active
February 28, 2020 21:53
-
-
Save ThomasG77/947212b91b57e69e25982dadb77afcf6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
from qgis.utils import plugins | |
from qgisnetworklogger.model import (RequestDetailsItem, | |
RequestHeadersItem, ReplyDetailsItem, ReplyHeadersItem) | |
def process_record_to_json(record): | |
_, tot = record.progress | |
reply_children = record.children[0].children | |
response_children = record.children[1].children | |
reply_value = {j.description: j.value for j in reply_children if isinstance(j, RequestDetailsItem)} | |
reply_value['headers'] = {k.description: k.value for k in [j for j in reply_children if isinstance(j, RequestHeadersItem)][0].children} | |
response_status = {k.description: k.value for k in response_children if isinstance(k, ReplyDetailsItem)} | |
response_cache = {k.description: k.value for k in response_children if isinstance(k, RequestDetailsItem)} | |
response_value = {**response_status, **response_cache} | |
response_value["headers"] = {l.description: l.value for l in [k for k in response_children if isinstance(k, ReplyHeadersItem)][0].children} | |
# TODO: manage PostContentItem | |
jsoncontent = { | |
"id": record.id, | |
"operation": record.operation, | |
"url": record.url.toString(), | |
"http_status": record.http_status, | |
"content_type": record.content_type, | |
"time_ms": record.time, | |
"bytes": tot, | |
"replies": record.replies, | |
"reply": reply_value, | |
"response": response_value | |
} | |
return jsoncontent | |
outfile = '/tmp/out.json' | |
with open(outfile, 'w') as f: | |
json_object = [] | |
for record in plugins['qgisnetworklogger'].logger.root_item.children: | |
json_object.append(process_record_to_json(record)) | |
f.write(json.dumps(json_object, indent=2)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment