-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUpdater.py
94 lines (83 loc) · 3.98 KB
/
Updater.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
83
84
85
86
87
88
89
90
91
92
93
94
import feedparser
import time
import socket
import threading
class RssThread(threading.Thread):
def __init__(self, rss_url, file_name):
self.rss_url = rss_url
self.file_name = file_name
super().__init__()
def run(self):
while True:
# Get Previous contents
with open(self.file_name, 'r') as file:
prev_contents = file.read()
# Check and extract data for QUOTE and SPECIAL
if self.rss_url == rss_links[3][0] or self.rss_url == rss_links[6][0]:
try:
feed = feedparser.parse(self.rss_url)
if feed.entries:
with open(self.file_name, 'w') as file:
file.write('<hr>')
count = 1
for entry in feed.entries:
file.write('<h2>' + entry.title + '</h2>'+ '<p>"' + entry.description + '"</p>'+'<hr>')
count+=1
if count == 3:
break
except:
with open(self.file_name, 'w') as file:
file.write(prev_contents)
# Check and extract data for P-NUMBER
elif self.rss_url == rss_links[5][0]:
try:
feed = feedparser.parse(self.rss_url)
if feed.entries:
with open(self.file_name, 'w') as file:
entry = feed.entries[0]
file.write(entry.title+'\n'+entry.description)
except:
with open(self.file_name, 'w') as file:
file.write(prev_contents)
# Extract data for other pages
else:
try:
feed = feedparser.parse(self.rss_url)
if feed.entries:
with open(self.file_name, 'w') as file:
count = 1
for entry in feed.entries:
file.write('<h2>' + entry.title + '</h2>'+'<hr>')
count+=1
if count == num:
break
except:
with open(self.file_name, 'w') as file:
file.write(prev_contents)
# Also extract top label from updates
if self.rss_url == rss_links[0][0]:
with open('rss/top.txt', 'r') as file:
prev_contents = file.read()
try:
feed = feedparser.parse(self.rss_url)
if feed.entries:
with open('rss/top.txt', 'w') as file:
entry = feed.entries[0]
entry2 = feed.entries[1]
file.write(entry.title+'\t\t'+entry2.title)
except:
with open('rss/top.txt', 'w') as file:
file.write(prev_contents)
rss_links = [
('https://1-updates.blogspot.com/feeds/posts/default?alt=rss', 'rss/updates.txt'),
('https://2-notices.blogspot.com/feeds/posts/default?alt=rss', 'rss/notices.txt'),
('https://3-event.blogspot.com/feeds/posts/default?alt=rss', 'rss/events.txt'),
('https://4-quote.blogspot.com/feeds/posts/default?alt=rss', 'rss/quote.txt'),
('https://5-placements.blogspot.com/feeds/posts/default?alt=rss', 'rss/placements.txt'),
('https://6-placed.blogspot.com/feeds/posts/default?alt=rss', 'rss/placed.txt'),
('https://7-specials.blogspot.com/feeds/posts/default?alt=rss', 'rss/special.txt')
]
num = 10
threads = [RssThread(*link) for link in rss_links]
for thread in threads:
thread.start()