-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwp_atom.py
executable file
·48 lines (39 loc) · 1.23 KB
/
wp_atom.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
#!/usr/bin/python3
import sys
import datetime
sys.path.append("../wiki_bayes/")
from wiki_important import get_a_page
def page_to_link(page):
from urllib.parse import quote
return "http://fr.wikipedia.org/wiki/%s" % quote(page)
def add_to_json(json_file="wikipedia.json"):
import json
try:
data = json.load(open(json_file))
except:
data = {}
today = str(datetime.date.today())
if today not in data:
data[today] = get_a_page()[0]
with open(json_file, "w") as fp:
json.dump(data, fp, indent=4)
return data
def atom():
data = add_to_json()
result = ""
result += '<?xml version="1.0" encoding="utf-8"?>\n'
result += '<feed xmlns="http://www.w3.org/2005/Atom">\n\n'
result += ' <title>Wikipedia fr</title>\n'
for date in sorted(data, reverse=True):
datef = date + "T11:00:00Z"
title = data[date]
link = page_to_link(title)
result += ' <entry>\n'
result += ' <title>%s</title>\n' % title
result += ' <link href="%s"/>\n' % link
result += ' <updated>%s</updated>\n' % datef
result += ' </entry>\n'
result += '\n</feed>\n'
return result
if __name__ == '__main__':
print(atom())