-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
executable file
·34 lines (26 loc) · 881 Bytes
/
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
#!/usr/bin/env python3
import os
import asyncio
import aiohttp
import logging
import logging.config
from dotenv import load_dotenv
from nyt_haiku import models, nyt, twitter
from nyt_haiku.haiku import HaikuFinder
load_dotenv()
logger = logging.getLogger()
logging.config.fileConfig('logconfig.ini')
async def main():
logger.info("Starting run...")
db_path = os.getenv("DB_PATH")
haiku_finder = HaikuFinder()
await models.init(db_path)
connector = aiohttp.TCPConnector(limit_per_host=15)
async with aiohttp.ClientSession(connector=connector) as session:
await nyt.check_sections(session, logger)
await nyt.fetch_articles(session, logger, haiku_finder)
if os.getenv("DISABLE_TWITTER") != 'true':
await twitter.tweet(session, logger)
await models.close_db()
logger.info("Ending run...")
asyncio.run(main())