-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathrun.py
More file actions
32 lines (27 loc) · 731 Bytes
/
run.py
File metadata and controls
32 lines (27 loc) · 731 Bytes
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
from app import app
from db import db
from models import article, source
import routes
import feed
from threading import Thread
import time
with app.app_context():
db.create_all()
def update_loop():
while True:
with app.app_context():
query = source.Source.query
for src in query.all():
try:
update_source(src)
except:
continue
time.sleep(60 * 15)
def update_source(src):
parsed = feed.parse(src.feed)
feed_articles = feed.get_articles(parsed)
article.Article.insert_from_feed(src.id, feed_articles)
print('Updated ' + src.feed)
thread = Thread(target=update_loop)
thread.start()
app.run()