-
Notifications
You must be signed in to change notification settings - Fork 0
/
report.py
78 lines (70 loc) · 2.07 KB
/
report.py
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import logging
from fastapi.responses import HTMLResponse
def create_report(entries, feed):
"""
Creates the html report
:param entries: news which were parsed
:param feed: instance of a feed class
:return: nothing, creates the actual html report file
"""
feed_name = feed.get_name()
html_content = """
<html>
<head>
<title>{0} News</title>
<style>
body {{
font-family: Arial, sans-serif;
}}
.panel {{
background-color: #ffffff;
border: 1px solid #ccc;
border-radius: 5px;
margin: 10px 0;
padding: 10px;
cursor: pointer;
}}
.panel-title {{
font-size: 18px;
font-weight: bold;
}}
.panel-content {{
display: none;
margin-top: 10px;
}}
</style>
<script>
function togglePanelContent(panel) {{
var content = panel.querySelector('.panel-content');
if (content.style.display === 'none' || content.style.display === '') {{
content.style.display = 'block';
}} else {{
content.style.display = 'none';
}}
}}
</script>
</head>
<body>
<h1>{0} News</h1>
""".format(feed_name)
entry_key = feed.get_entry_key()
for entry in entries:
html_content += f"""
<div class="panel" onclick="togglePanelContent(this)">
<div class="panel-title">{entry['title']}</div>
<div class="panel-content">
<p><strong>Link:</strong> <a href="{entry['link']}">{entry['link']}</a></p>
<p><strong>AI Summary:</strong> {entry[entry_key]}</p>
</div>
</div>
"""
html_content += """
</body>
</html>
"""
logging.info("Starting report creation")
filename = f"{feed_name}NewsBoard.html"
with open(filename, "w", encoding="utf-8") as file:
file.write(html_content)
logging.info(f"The {feed_name} entries have been saved.")
return HTMLResponse(content=html_content)