-
Notifications
You must be signed in to change notification settings - Fork 0
/
rss-syn.py
32 lines (26 loc) · 1005 Bytes
/
rss-syn.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
#!/usr/bin/python3
__author__ = 'Heyu Lin'
import os
import hashlib
import requests
import time
rss_local = 'environmental-microbiology.rss'
rss_url = 'https://www.nature.com/subjects/environmental-microbiology.rss'
rss_file = requests.get(rss_url)
time_now = time.asctime(time.localtime(time.time()))
if not os.path.exists(rss_local):
with open(rss_local, 'wb') as f:
f.write(rss_file.content)
with open('history.log', 'a') as flog:
flog.write('{0}\t{1}\n'.format(time_now, 'init'))
else:
md5_new = hashlib.md5(rss_file.content.decode("utf8").encode("utf8")).hexdigest()
md5_old = hashlib.md5(rss_local.encode("utf8")).hexdigest()
if md5_new != md5_old:
with open(rss_local, 'wb') as f:
f.write(rss_file.content)
with open('history.log', 'a') as flog:
flog.write('{0}\t{1}\n'.format(time_now, 'updated'))
else:
with open('history.log', 'a') as flog:
flog.write('{0}\t{1}\n'.format(time_now, 'NC'))