-
Notifications
You must be signed in to change notification settings - Fork 1
/
rss.py
64 lines (56 loc) · 2.27 KB
/
rss.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
import feedparser
import json
import os
import datetime
import time
from dateutil.parser import parse
def rss(url, last_modified=None):# store the etag and modified
if(last_modified == None):
feed_update = feedparser.parse(url)
else:
feed_update = feedparser.parse(url, modified = last_modified)
filename = 'savedata.json'
with open(filename, 'r') as f:
savefile = json.load(f)
last_post_date = savefile['savedata']["rss.py"]["modified"]
if (( duplicateCheck(last_post_date, feed_update["entries"][0]["published"]))): #("2023-01-29 23:09:25.052002", "2023-01-30 23:09:25.052002") )):
filename = 'savedata.json'
with open(filename, 'r') as f:
data = json.load(f)
data['savedata']["rss.py"]["modified"] = feed_update["entries"][0]["published"]
os.remove(filename)
with open(filename, 'w') as f:
json.dump(data, f, indent=4)
#print(feed_update["entries"][0])
text = feed_update["entries"][0]["summary"]
text = text.replace("\t", "")
text = text.replace("\n \n\n\n", "\n\n")
title = feed_update["entries"][0]["title"]
link = feed_update["entries"][0]["link"]
pubdate = feed_update["entries"][0]["published"]
print()
print("New post in RSS feed: " + title + " " + pubdate)
print(repr(text))
return (True, text, title, link, pubdate)
else:
return (False, None, None, None)
def heliohostrss():
filename = 'savedata.json'
with open(filename, 'r') as f:
data = json.load(f)
return rss("https://www.helionet.org/index/rss/1-news.xml/", data['savedata']["rss.py"]["modified"])
def duplicateCheck(oldtime, newtime):
oldtime = oldtime.replace("+0000", "")
oldtime = oldtime.replace("GMT", "")
oldtime = parse(oldtime.split(".", 1)[0])
oldtime = (time.mktime(oldtime.timetuple()))
newtime = newtime.replace("+0000", "")
newtime = newtime.replace("GMT", "")
newtime = parse(newtime.split(".", 1)[0])
newtime = (time.mktime(newtime.timetuple()))
if (str(oldtime) < (str(newtime))):
return True
else:
return False
if __name__ == "__main__":
exit("Don't Run This File as a Standalone File! Import it into another file to use it")