-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
34 lines (29 loc) · 1.28 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
import logging
from blinkist_scraper import BlinkistScraper
from book_converter import Format
from book_to_epub_converter import BookToEpubConverter
from book_to_markdown_converter import BookToMarkDownConverter
from book_to_html_converter import BookToHtmlConverter
from email_service import EmailService, SenderFactory, Receiver, ReceiverFactory
def cronjob():
logging.basicConfig(level=logging.INFO)
scraper = BlinkistScraper('config.json')
#scraper = BlinkistScraperMock()
books = scraper.scrape()
md_converter = BookToMarkDownConverter('blinkist/md')
epub_converter = BookToEpubConverter('blinkist/epub')
html_converter = BookToHtmlConverter('blinkist/html')
email = EmailService(sender=SenderFactory.sender('config.json'))
receivers = ReceiverFactory.receivers('config.json')
for book in books:
filenames= dict()
filenames[Format.MarkDown] = md_converter.convert(book)
filenames[Format.EPUB] = epub_converter.convert(book)
filenames[Format.HTML] = html_converter.convert(book)
for receiver in receivers:
email.send_email([receiver],
'Your Daily Blink',
'',
filenames[receiver.format])
if __name__ == "__main__":
cronjob()