forked from E-P-T/Homework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconverter.py
More file actions
49 lines (41 loc) · 1.49 KB
/
converter.py
File metadata and controls
49 lines (41 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from loguru import logger
import json
from json2html import *
class Converter:
"""
Convert from: object to dict
json to dict
dict to json
json to HTML
"""
def __init__(self, my_reader=None) -> None:
self.my_reader = my_reader
def to_dict(self) -> dict:
logger.debug("Convert data to dictionary (debug)!")
dict = {"name": self.my_reader.name,
"size": self.my_reader.limit,
"title": self.my_reader.title,
"pubDate": self.my_reader.pubDate,
"description": self.my_reader.clear_description,
"link": self.my_reader.link}
return dict
def from_json(self) -> dict:
logger.debug("Read data from json(debug)!")
with open('data.json') as json_file:
data = json.load(json_file)
return data
def to_JSON(self, dict=False) -> None:
if not dict:
dict = self.to_dict()
logger.debug("Convert data to json (debug)!")
with open('data.json', 'w+') as outfile:
json.dump(dict, outfile, indent=4)
def to_HTML(self):
with open("data.json") as f:
d = json.load(f)
scanOutput = json2html.convert(json=d)
htmlReportFile = "output.html"
with open(htmlReportFile, 'w') as htmlfile:
htmlfile.write(str(scanOutput))
print("Data save in output.html")
return True