Weather Pipeline
SingletonMeta
Bases: type
A metaclass for creating singleton classes.
Source code in WeatherPipeline.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | |
__call__(*args, **kwargs)
Possible changes to the value of the __init__ argument do not affect
the returned instance.
If the class has not been instantiated yet, create a new instance.
If it has, return the existing instance.
Source code in WeatherPipeline.py
23 24 25 26 27 28 29 30 31 32 33 | |
WeatherPipeline
A class to handle the weather data pipeline.
Source code in WeatherPipeline.py
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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | |
__init__()
Initialize the WeatherPipeline class and set up the database connection.
DuckDB is used to manage the weather data locations.
This constructor initializes the database connection and creates the necessary table for storing weather locations if it does not already exist.
Source code in WeatherPipeline.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | |
add_location(postcode)
Add a new location to the weather data pipeline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
postcode
|
str
|
The postcode of the location to add. |
required |
Raises:
| Type | Description |
|---|---|
Exception
|
If the location cannot be added due to a database error. |
Source code in WeatherPipeline.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | |
get_and_write_forecast_history(date, location, writer, destination)
Fetch and write the weather forecast history for a specific date and location.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
date
|
str
|
The date for which to fetch the forecast history. |
required |
location
|
str
|
The location for which to fetch the forecast history. |
required |
writer
|
Writer
|
An instance of the Writer class to handle writing data. |
required |
destination
|
str
|
The file path where the data should be written. |
required |
Raises:
| Type | Description |
|---|---|
Exception
|
If the data cannot be fetched or written successfully. |
Source code in WeatherPipeline.py
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | |
get_locations()
Retrieve all locations from the weather data pipeline.
Returns:
| Name | Type | Description |
|---|---|---|
list |
list
|
A list of postcodes for the locations stored in the database. |
Raises:
| Type | Description |
|---|---|
Exception
|
If the locations cannot be retrieved due to a database error. |
Source code in WeatherPipeline.py
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | |
remove_location(postcode)
Remove a location from the weather data pipeline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
postcode
|
str
|
The postcode of the location to remove. |
required |
Raises:
| Type | Description |
|---|---|
Exception
|
If the location cannot be removed due to a database error. |
Source code in WeatherPipeline.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | |