-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhtmlReportGenerator.py
82 lines (76 loc) · 2.93 KB
/
htmlReportGenerator.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
79
80
81
82
# Read the list of items in ofInterest.json and create an HTML report of the items.
import json
import pandas as pd
import yaml
import html
def load_articles_from_json(file_path):
"""
Load articles from a JSON file and return them as a list of dictionaries.
Args:
file_path (str): The path to the JSON file.
Returns:
list: A list of dictionaries, where each dictionary represents an article.
"""
try:
with open(file_path, 'r') as file:
articles = json.load(file)
if not isinstance(articles, list):
raise ValueError("JSON file does not contain a list of articles")
return articles
except json.JSONDecodeError:
print(f"Error: The file at {file_path} is not valid JSON.")
return []
except FileNotFoundError:
print(f"Error: The file at {file_path} was not found.")
return []
except Exception as e:
print(f"An unexpected error occurred: {str(e)}")
return []
def main():
# colourPath = "data/theme/catppuccin-Mocha.css"
# Get theme from config.yaml
with open("config.yaml", 'r') as f:
config = yaml.safe_load(f)
themeName = config['theme']
colourPath = f"data/theme/{themeName}.css"
with open(colourPath, 'r') as f:
style = f.read()
stylePath = "style.css"
with open(stylePath, 'r') as f:
style += f.read()
# Read the list of items in ofInterest.json
items = load_articles_from_json('./data/ratedArticles.json')
# Create an HTML report of the items
html_report =f"""
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Daily ArXiv Roundup</title>
<link rel="icon" href="icon.svg" type="image/x-icon">
<style>
{style}
</style>
</head>
"""
# This loops over all the items in the list and creates a div for each item
for index, item in enumerate(items):
html_report += "<div class='item-box'>"
html_report += f"<h2>{index+1}. {item['title']}</h2>"
html_report += f"<p><strong>Abstract: </strong>{item['abstract']}</p>"
html_report += f"<a href='{item['link']}' class='button'>Read More</a>"
html_report += f"<a href='{item['pdf']}' class='button'>PDF</a>"
html_report += "<div class='rating-bar-container'>"
html_report += f"<div class='rating-bar' style='width: {item['Rating']*100}%'></div>"
html_report += "</div>"
html_report += f"<p><strong>Rating: </strong>{item['Rating']}</p>"
html_report += f"<p><strong>Justification: </strong>{item['Justification']}</p>"
html_report += "</div>"
html_report += "</main></html>"
# Save the HTML report to a file
with open('./report.html', 'w') as file:
file.write(html_report)
print("HTML report generated successfully!")
if __name__=="__main__":
main()