-
Notifications
You must be signed in to change notification settings - Fork 0
/
prep-recent-news.py
38 lines (33 loc) · 1.18 KB
/
prep-recent-news.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
# written by Mohammad Shahrad @UBC
RECENT_NEWS_COUNT = 5
import json
with open("./all-news.json") as f:
allNews = json.load(f)
recent_news_counter = 0
with open("./recent-news.js", "w") as f:
f.write("document.write('\\\n")
f.write("<ul style=\"text-align: left;vertical-align: top;\">\\\n")
for value in allNews.values():
f.write("<li>\\\n")
date, content = value["date"], value["content"]
date = date.replace("'", "\\'")
content = content.replace("'", "\\'")
f.write(date + " - " + content + "\\\n")
f.write("</li>\\\n")
recent_news_counter += 1
if recent_news_counter >= RECENT_NEWS_COUNT:
break
f.write("</ul>\\\n")
f.write("');")
with open("./all-news.js", "w") as f:
f.write("document.write('\\\n")
f.write("<ul style=\"text-align: left;vertical-align: top;\">\\\n")
for value in allNews.values():
f.write("<li>\\\n")
date, content = value["date"], value["content"]
date = date.replace("'", "\\'")
content = content.replace("'", "\\'")
f.write(date + " - " + content + "\\\n")
f.write("</li>\\\n")
f.write("</ul>\\\n")
f.write("');")