-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
43 lines (30 loc) · 989 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
35
36
37
38
39
40
41
42
43
from typing import List
import logging.config
from scraper_news import ScraperNews, argparse_setup, Filemanager
import scraper_news
def main():
args = argparse_setup()
if args.count:
count_news()
if args.scrape:
scrape_news(args.sources, args.breaking)
if args.show:
scraper_news.show_news_in_time_frame(args.sources, args.hours, args.breaking)
def scrape_news(sources: List[str], is_breaking: bool):
for source in sources:
s = ScraperNews(source, is_breaking)
s.get_news()
s.print_news()
s.save_news()
def count_news() -> None:
news = Filemanager.get_news_data()
for source_name, news_list in news.items():
print(f"\n{source_name.upper()}")
print(f"Number of news: {len(news_list)}")
print()
if __name__ == "__main__":
logging.config.fileConfig(
fname=Filemanager.logging_ini_path,
defaults={"logfilename": Filemanager.logfile_path},
)
main()