-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmain.py
50 lines (42 loc) · 1.66 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
import concurrent.futures
import time
import traceback
import miniflux
import schedule
from common import Config, logger
from myapp import app
from core import fetch_unread_entries, generate_daily_news
config = Config()
miniflux_client = miniflux.Client(config.miniflux_base_url, api_key=config.miniflux_api_key)
while True:
try:
alive = miniflux_client.me()
logger.info('Successfully connected to Miniflux!')
break
except Exception as e:
logger.error('Cannot connect to Miniflux: %s' % e)
time.sleep(1)
def my_schedule():
interval = 15 if config.miniflux_webhook_secret else 1
schedule.every(interval).minutes.do(fetch_unread_entries, config, miniflux_client)
schedule.run_all()
if config.ai_news_schedule:
feeds = miniflux_client.get_feeds()
if not any('Newsᴬᴵ for you' in item['title'] for item in feeds):
try:
miniflux_client.create_feed(category_id=1, feed_url=config.ai_news_url + '/rss/ai-news')
logger.info('Successfully created the ai_news feed in Miniflux!')
except Exception as e:
logger.error('Failed to create the ai_news feed in Miniflux: %s' % e)
for ai_schedule in config.ai_news_schedule:
schedule.every().day.at(ai_schedule).do(generate_daily_news, miniflux_client)
while True:
schedule.run_pending()
time.sleep(1)
def my_flask():
logger.info('Starting API')
app.run(host='0.0.0.0', port=80)
if __name__ == '__main__':
with concurrent.futures.ThreadPoolExecutor(max_workers=2) as executor:
executor.submit(my_flask)
executor.submit(my_schedule)