-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
59 lines (50 loc) · 1.72 KB
/
main.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
from flask import *
import feedparser
import threading
app = Flask(__name__)
app.secret_key = 'shivam bansal'
#first parsing
dht = feedparser.parse('http://feeds.hindustantimes.com/HT-IndiaSectionPage-Topstories')
dzn = feedparser.parse('http://zeenews.india.com/rss/india-national-news.xml')
die = feedparser.parse('http://syndication.indianexpress.com/rss/latest-news.xml')
secs = 120
def normal():
new_content = ""
jsfile = open("static/js/timer.js", "rt")
for line in jsfile:
new_content = new_content + line.replace("location","//location")
jsfile.close()
f = open('static/js/timer.js','w')
f.write(new_content)
f.close()
def make_request():
global d
global secs
interval = secs/10
x = feedparser.parse('http://feeds.hindustantimes.com/HT-IndiaSectionPage-Topstories', etag=dht.etag)
y = feedparser.parse('http://zeenews.india.com/rss/india-national-news.xml', etag=dzn.etag)
z = feedparser.parse('http://syndication.indianexpress.com/rss/latest-news.xml', etag=die.etag)
if x.status == 304 or y.status == 304 or z.status == 304:
#not changed, increase the interval
d1 = x
secs = secs + interval
else:
#changed, reload and decrease the interval
secs = secs - interval
new_content = ""
jsfile = open("static/js/timer.js", "rt")
for line in jsfile:
new_content = new_content + line.replace("//location","location")
jsfile.close()
f = open('static/js/timer.js','w')
f.write(new_content)
f.close()
threading.Timer(2, normal).start()
@app.route('/')
def index():
global secs
threading.Timer(secs, make_request).start()
return render_template('index.html', collection = dht.entries, collection2 = die.entries, collection3 = dzn.entries)
#Run server
if __name__ == '__main__' :
app.run(debug=True)