Skip to content
Snippets Groups Projects
Commit d083589e authored by Ciro Brodmann's avatar Ciro Brodmann
Browse files

added a simple log converter

parent 410793c9
No related branches found
No related tags found
No related merge requests found
Pipeline #282200 passed with stage
in 2 minutes and 4 seconds
export.csv
info.log
info.log.old
.DS_Store
import json
from pathlib import Path
from csv import DictWriter
# from urllib.parse import unquote_plus
def main():
logfile_path = Path('info.log')
export_path = Path('export.csv')
with logfile_path.open('r') as logs:
log_entries = [
json.loads(line.strip())
for line in logs.readlines()
if line.strip() != ''
]
logs.seek(0)
with export_path.open('w') as csv:
writer = DictWriter(csv, ['search_keywords', 'search_results', 'timestamp', 'comment'])
writer.writeheader()
filtered_entries = [
{
# 'search_keywords': unquote_plus(log['submission']['search']),
'search_keywords': log['submission']['search'],
'search_results': json.dumps(log['submission']['rawSearchResult']),
'timestamp': log['timestamp'],
'comment': log['submission']['comment'] if 'comment' in log['submission'] else '',
}
for log in log_entries
if log['task'] == 'resultSubmission' and not log['submission']['success']
]
writer.writerows(filtered_entries)
print(f'Converted {len(filtered_entries)} objects to CSV')
if __name__ == '__main__':
main()
# This file is automatically @generated by Poetry 1.4.2 and should not be changed by hand.
[[package]]
name = "decorator"
version = "5.1.1"
description = "Decorators for Humans"
category = "main"
optional = false
python-versions = ">=3.5"
files = [
{file = "decorator-5.1.1-py3-none-any.whl", hash = "sha256:b8c3f85900b9dc423225913c5aace94729fe1fa9763b38939a95226f02d37186"},
{file = "decorator-5.1.1.tar.gz", hash = "sha256:637996211036b6385ef91435e4fae22989472f9d571faba8927ba8253acbc330"},
]
[[package]]
name = "jsonpath-ng"
version = "1.5.3"
description = "A final implementation of JSONPath for Python that aims to be standard compliant, including arithmetic and binary comparison operators and providing clear AST for metaprogramming."
category = "main"
optional = false
python-versions = "*"
files = [
{file = "jsonpath-ng-1.5.3.tar.gz", hash = "sha256:a273b182a82c1256daab86a313b937059261b5c5f8c4fa3fc38b882b344dd567"},
{file = "jsonpath_ng-1.5.3-py2-none-any.whl", hash = "sha256:f75b95dbecb8a0f3b86fd2ead21c2b022c3f5770957492b9b6196ecccfeb10aa"},
{file = "jsonpath_ng-1.5.3-py3-none-any.whl", hash = "sha256:292a93569d74029ba75ac2dc3d3630fc0e17b2df26119a165fa1d498ca47bf65"},
]
[package.dependencies]
decorator = "*"
ply = "*"
six = "*"
[[package]]
name = "pathlib"
version = "1.0.1"
description = "Object-oriented filesystem paths"
category = "main"
optional = false
python-versions = "*"
files = [
{file = "pathlib-1.0.1-py3-none-any.whl", hash = "sha256:f35f95ab8b0f59e6d354090350b44a80a80635d22efdedfa84c7ad1cf0a74147"},
{file = "pathlib-1.0.1.tar.gz", hash = "sha256:6940718dfc3eff4258203ad5021090933e5c04707d5ca8cc9e73c94a7894ea9f"},
]
[[package]]
name = "ply"
version = "3.11"
description = "Python Lex & Yacc"
category = "main"
optional = false
python-versions = "*"
files = [
{file = "ply-3.11-py2.py3-none-any.whl", hash = "sha256:096f9b8350b65ebd2fd1346b12452efe5b9607f7482813ffca50c22722a807ce"},
{file = "ply-3.11.tar.gz", hash = "sha256:00c7c1aaa88358b9c765b6d3000c6eec0ba42abca5351b095321aef446081da3"},
]
[[package]]
name = "six"
version = "1.16.0"
description = "Python 2 and 3 compatibility utilities"
category = "main"
optional = false
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*"
files = [
{file = "six-1.16.0-py2.py3-none-any.whl", hash = "sha256:8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254"},
{file = "six-1.16.0.tar.gz", hash = "sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926"},
]
[metadata]
lock-version = "2.0"
python-versions = "^3.9"
content-hash = "376818fde5a59ad2ba8812d7f07fefbe2a3308310c51ffc6a69b50fb796de2cc"
[tool.poetry]
name = "logconverter"
version = "0.1.0"
description = ""
authors = ["Ciro Brodmann <ciro.brodmann@ost.ch>"]
readme = "README.md"
[tool.poetry.dependencies]
python = "^3.9"
pathlib = "^1.0.1"
jsonpath-ng = "^1.5.3"
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment