diff --git a/.idea/aws.xml b/.idea/aws.xml new file mode 100644 index 0000000..03f1bb6 --- /dev/null +++ b/.idea/aws.xml @@ -0,0 +1,17 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..c110c82 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..4bc789d --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..8306744 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/weather_forecase.iml b/.idea/weather_forecase.iml new file mode 100644 index 0000000..6cb8b9a --- /dev/null +++ b/.idea/weather_forecase.iml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..184e3db --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + { + "associatedIndex": 0 +} + + + + + + + + + + + + + + + + 1708266714436 + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..a58c0d4 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,20 @@ +FROM python:3.13-rc-alpine3.19 +# Upgrade alpine OS +RUN apk update && apk upgrade +# Create log dir and file +RUN mkdir /results +# Go to application directoy and copy code +WORKDIR /app +COPY requirements.txt requirements.txt +COPY main.py main.py +COPY src/. /app/src/ +# Upgrade pip version +RUN pip3 install --upgrade pip +# Install python packages +RUN pip3 install -r requirements.txt +#Call python code +CMD ["python", "-m", "main"] + + +#sudo docker run --rm -d -p 3159:3159/udp -v /tmp/omada_logs/:/omada_logs/ jacob/udp_server +# /volume1/Docker/wheather_api/results:/results/ diff --git a/main.py b/main.py index 7b87c74..8dcf6d9 100644 --- a/main.py +++ b/main.py @@ -1,15 +1,19 @@ import src.wheaterAPI as wapi import time from datetime import datetime +from datetime import timedelta import logging def main(): logging.basicConfig(level=logging.INFO) - wheather_api_current = wapi.WheatherAPI() - wheater_api_forecast = wapi.WheatherAPI() max_forecast = 3 - last_datetime = datetime.now().strftime('%Y-%m-%d-%H') + bucket_name = 'bucket weather_data_2024' + folder_current = 'current_test' + folder_forecast = 'forecast_test' + wheather_api_current = wapi.WheatherAPI(bucket_name, folder_current) + wheater_api_forecast = wapi.WheatherAPI(bucket_name, folder_forecast) + last_datetime = (datetime.now() + timedelta(hours=-1)).strftime('%Y-%m-%d-%H') next_run = datetime.today().strftime('%Y-%m-%d') hour_of_forecast_run = datetime.now().strftime('%H') logging.info('The max_forecast variable has the value: ' + str(max_forecast)) diff --git a/requirements.txt b/requirements.txt index c1eccff..2478bdb 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,5 +2,4 @@ setuptools wheel requests datetime -google-cloud-storage diff --git a/src/lambda_function/parse_to_dynamodb.py b/src/lambda_function/parse_to_dynamodb.py new file mode 100644 index 0000000..e69de29 diff --git a/src/wheaterAPI.py b/src/wheaterAPI.py index 00bfdeb..69bc3ff 100644 --- a/src/wheaterAPI.py +++ b/src/wheaterAPI.py @@ -6,9 +6,11 @@ import logging class WheatherAPI(): - def __init__(self): + def __init__(self, bucket_name, folder_name): self.current_url = 'http://api.weatherapi.com/v1/current.json?key=6b0654bd658842b085395550230406&q=location&aqi=no' self.forecast_url = 'http://api.weatherapi.com/v1/forecast.json?key=6b0654bd658842b085395550230406&q=location&days=no_days&aqi=no&alerts=no' + self.bucket_name = bucket_name + self.folder_name = folder_name def current_wheather(self, location): @@ -20,9 +22,11 @@ class WheatherAPI(): filename = 'current_' + location + '_' + datetime.now().strftime('%Y-%m-%d-%H-%M') + '.json' - with open(os.path.join('C:/Users/jacob/PycharmProjects/AWS-Training/results/current', filename) ,'w') as file: #/results/current/ + with open(os.path.join('C:/Users/jacob/PycharmProjects/GCP-Weather-Forecast/current', filename) ,'w') as file: #/results/current/ json.dump(data, file) + + def forecast_wheather(self, location, no_days): url = self.forecast_url.replace('location', location) @@ -34,7 +38,7 @@ class WheatherAPI(): filename = 'forecasts_' + location + '_' + str(no_days) + '_' + datetime.now().strftime('%Y-%m-%d-%H-%M') + '.json' - with open(os.path.join('C:/Users/jacob/PycharmProjects/AWS-Training/results/forecasts', filename), 'w') as file: #/results/forecasts/ + with open(os.path.join('C:/Users/jacob/PycharmProjects/GCP-Weather-Forecast/forecasts', filename), 'w') as file: #/results/forecasts/ json.dump(data, file) def call_current_wheater(self, last_datetime, location_list):