-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
38 lines (30 loc) · 938 Bytes
/
run.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
from time import sleep
import feedparser
import requests
from calls.master import Publishing
from parameters import SECONDS_IN_MINUTE, FEED_URL
from repos.news import NewsRepository
def _remove(news):
for n in news:
f = requests.get(n['link']).text
if '<b>kohtuasjaga seotud dokumente ei leitud</b>' in f:
news.remove(n)
print('Not collecting news with URL=%s' % n['link'])
return news
def _collect():
feed = feedparser.parse(FEED_URL)
news = feed['entries']
news = _remove(news)
print('Collecting news')
NewsRepository().save_news(news)
def _publish():
news = NewsRepository().get_unpublished()
for a_news in news:
Publishing().publish_one(a_news)
if __name__ == '__main__':
while True:
_collect()
_publish()
minutes = 15
print('Will sleep for %d minutes' % minutes)
sleep(minutes * SECONDS_IN_MINUTE)