-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathload.py
63 lines (51 loc) · 1.84 KB
/
load.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
51
52
53
54
55
56
57
58
59
60
61
62
63
from datetime import date, datetime
import typer
from src.email.send_email import send_email
from src.etls.boe.scrapper import BOEScrapper
from src.etls.common.etl import ETL
from src.etls.utils import catch_exceptions
from src.etls.boe.defs import COLLECTION_NAME
from src.initialize import initialize_app
app = typer.Typer()
@app.command()
@catch_exceptions(cancel_on_failure=True)
def today(init_objects=None):
if init_objects is None:
init_objects = initialize_app()
etl_job = ETL(config_loader=init_objects.config_loader, vector_store=init_objects.vector_store[COLLECTION_NAME])
boe_scrapper = BOEScrapper()
day = date.today()
docs = boe_scrapper.download_day(day)
if docs:
etl_job.run(docs)
subject = "[BOE] Daily ETL executed"
content = f"""
Daily ETL executed
- Date: {day}
- Documents loaded: {len(docs)}
- Database used: {init_objects.config_loader['vector_store']}
"""
send_email(init_objects.config_loader, subject, content)
@app.command()
def dates(date_start: str, date_end: str, init_objects=None):
if init_objects is None:
init_objects = initialize_app()
etl_job = ETL(config_loader=init_objects.config_loader, vector_store=init_objects.vector_store[COLLECTION_NAME])
boe_scrapper = BOEScrapper()
docs = boe_scrapper.download_days(
date_start=datetime.strptime(date_start, "%Y/%m/%d").date(),
date_end=datetime.strptime(date_end, "%Y/%m/%d").date(),
)
if docs:
etl_job.run(docs)
subject = "[BOE] Load ETL executed"
content = f"""
Load ETL executed
- Date start: {date_start}
- Date end: {date_end}
- Documents loaded: {len(docs)}
- Database used: {init_objects.config_loader['vector_store']}
"""
send_email(init_objects.config_loader, subject, content)
if __name__ == "__main__":
app()