Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.