-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathetl.py
49 lines (41 loc) · 1.48 KB
/
etl.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
"""
A module for etl in the pipeline package.
"""
import logging
from pydantic import FilePath
from pipeline.config.init_settings import init_settings
from pipeline.config.settings import settings
from pipeline.core.decorators import benchmark, with_logging
from pipeline.core.logging_setup import setup_logging
from pipeline.db.session import get_db
from pipeline.engineering.extraction import extract_api_data, extract_csv_data
from pipeline.engineering.loading import load_data
from pipeline.engineering.transformation import transform_data
from pipeline.models.weather import Weather
from pipeline.schemas.api.weather import APIWeather
from pipeline.schemas.files.weather import CSVWeather
setup_logging(init_settings)
logger: logging.Logger = logging.getLogger(__name__)
@with_logging
@benchmark
def main() -> None:
"""
The main function to execute the pipeline
:return: None
:rtype: NoneType
"""
logger.info("Data extraction")
api_weather_data: APIWeather = extract_api_data(settings)
filepath: FilePath = FilePath("data/raw/weatherAUS.csv")
csv_weather_data: list[CSVWeather] = extract_csv_data(
filepath, init_settings
)
logger.info("Data transformation")
weather: Weather = transform_data(csv_weather_data[0], api_weather_data)
with get_db() as session:
load_data(session, weather)
logger.info("Loaded data")
if __name__ == "__main__":
logger.info("Pipeline to be executed")
main()
logger.info("Pipeline finished")