-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtasks.py
executable file
·30 lines (22 loc) · 954 Bytes
/
tasks.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
from robocorp.tasks import task
from robocorp import workitems
from robocorp.tasks import get_output_dir
from libs.NewsScraper import NewsScraper
OUTPUT_DIR = get_output_dir()
TARGET_WEBSITE = "https://www.aljazeera.com/"
@task
def make_aljazeera_news_report():
scraper = NewsScraper()
try:
scraper.set_output_dir(OUTPUT_DIR / "aljazeera_news")
scraper.prepare_environment(browser="Chrome")
scraper.access_home_page(TARGET_WEBSITE)
for item in workitems.inputs:
search_phrase = item.payload.get("search_phrase", "Science")
number_of_months = item.payload.get("number_of_months", 1)
scraper.logger.info(f"Collected workitems: {search_phrase}, {number_of_months}")
scraper.collect_articles(search_phrase, number_of_months=number_of_months)
scraper.create_report()
scraper.archive_collection()
finally:
scraper.driver_quit()