Add lambda function to write json to dynamo db
This commit is contained in:
17
.idea/aws.xml
generated
Normal file
17
.idea/aws.xml
generated
Normal file
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="accountSettings">
|
||||
<option name="activeProfile" value="profile:default" />
|
||||
<option name="activeRegion" value="us-east-1" />
|
||||
<option name="recentlyUsedProfiles">
|
||||
<list>
|
||||
<option value="profile:default" />
|
||||
</list>
|
||||
</option>
|
||||
<option name="recentlyUsedRegions">
|
||||
<list>
|
||||
<option value="us-east-1" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
||||
6
.idea/inspectionProfiles/profiles_settings.xml
generated
Normal file
6
.idea/inspectionProfiles/profiles_settings.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<settings>
|
||||
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||
<version value="1.0" />
|
||||
</settings>
|
||||
</component>
|
||||
7
.idea/misc.xml
generated
Normal file
7
.idea/misc.xml
generated
Normal file
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Black">
|
||||
<option name="sdkName" value="Python 3.12 (weather_forecase)" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.12" project-jdk-type="Python SDK" />
|
||||
</project>
|
||||
8
.idea/modules.xml
generated
Normal file
8
.idea/modules.xml
generated
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/weather_forecase.iml" filepath="$PROJECT_DIR$/.idea/weather_forecase.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
7
.idea/vcs.xml
generated
Normal file
7
.idea/vcs.xml
generated
Normal file
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
10
.idea/weather_forecase.iml
generated
Normal file
10
.idea/weather_forecase.iml
generated
Normal file
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="PYTHON_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<excludeFolder url="file://$MODULE_DIR$/.venv" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="Python 3.12" jdkType="Python SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
126
.idea/workspace.xml
generated
Normal file
126
.idea/workspace.xml
generated
Normal file
@@ -0,0 +1,126 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="AutoImportSettings">
|
||||
<option name="autoReloadType" value="SELECTIVE" />
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="9a6512a2-4a65-46dc-ac79-ea908fa84d1f" name="Changes" comment="">
|
||||
<change afterPath="$PROJECT_DIR$/.idea/aws.xml" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/.idea/inspectionProfiles/profiles_settings.xml" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/.idea/modules.xml" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/.idea/vcs.xml" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/.idea/weather_forecase.iml" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/Dockerfile" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/main.py" beforeDir="false" afterPath="$PROJECT_DIR$/main.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/requirements.txt" beforeDir="false" afterPath="$PROJECT_DIR$/requirements.txt" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/wheaterAPI.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/wheaterAPI.py" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
||||
<option name="LAST_RESOLUTION" value="IGNORE" />
|
||||
</component>
|
||||
<component name="Git.Settings">
|
||||
<option name="PREVIOUS_COMMIT_AUTHORS">
|
||||
<list>
|
||||
<option value="hadoop <hadoop@jacob-fritsche.de>" />
|
||||
<option value="hadoop@jacob-fritsche.de" />
|
||||
<option value="Jacob Fritsche" />
|
||||
</list>
|
||||
</option>
|
||||
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
||||
</component>
|
||||
<component name="ProjectColorInfo">{
|
||||
"associatedIndex": 0
|
||||
}</component>
|
||||
<component name="ProjectId" id="2cXnIw4Lu5D1AWhPEOMqNA3ffhw" />
|
||||
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
|
||||
<component name="ProjectViewState">
|
||||
<option name="hideEmptyMiddlePackages" value="true" />
|
||||
<option name="showLibraryContents" value="true" />
|
||||
</component>
|
||||
<component name="PropertiesComponent"><![CDATA[{
|
||||
"keyToString": {
|
||||
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||
"ignore.virus.scanning.warn.message": "true",
|
||||
"last_opened_file_path": "C:/Users/jacob/PycharmProjects/GCP-Weather-Forecast",
|
||||
"node.js.detected.package.eslint": "true",
|
||||
"node.js.detected.package.tslint": "true",
|
||||
"node.js.selected.package.eslint": "(autodetect)",
|
||||
"node.js.selected.package.tslint": "(autodetect)",
|
||||
"nodejs_package_manager_path": "npm",
|
||||
"vue.rearranger.settings.migration": "true"
|
||||
}
|
||||
}]]></component>
|
||||
<component name="SharedIndexes">
|
||||
<attachedChunks>
|
||||
<set>
|
||||
<option value="bundled-python-sdk-d68999036c7f-b11f5e8da5ad-com.jetbrains.pycharm.pro.sharedIndexes.bundled-PY-233.14475.56" />
|
||||
</set>
|
||||
</attachedChunks>
|
||||
</component>
|
||||
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
|
||||
<component name="TaskManager">
|
||||
<task active="true" id="Default" summary="Default task">
|
||||
<changelist id="9a6512a2-4a65-46dc-ac79-ea908fa84d1f" name="Changes" comment="" />
|
||||
<created>1708266714436</created>
|
||||
<option name="number" value="Default" />
|
||||
<option name="presentableId" value="Default" />
|
||||
<updated>1708266714436</updated>
|
||||
<workItem from="1708266723501" duration="3881000" />
|
||||
<workItem from="1708716532861" duration="62000" />
|
||||
<workItem from="1708716653230" duration="68000" />
|
||||
<workItem from="1709141002289" duration="33000" />
|
||||
<workItem from="1709141085982" duration="184000" />
|
||||
<workItem from="1709141371555" duration="1607000" />
|
||||
</task>
|
||||
<task id="LOCAL-00001" summary="Initial code to get the weather data from the API">
|
||||
<option name="closed" value="true" />
|
||||
<created>1708266943635</created>
|
||||
<option name="number" value="00001" />
|
||||
<option name="presentableId" value="LOCAL-00001" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1708266943635</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00002" summary="Initial code to get the weather data from the API">
|
||||
<option name="closed" value="true" />
|
||||
<created>1708267080483</created>
|
||||
<option name="number" value="00002" />
|
||||
<option name="presentableId" value="LOCAL-00002" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1708267080483</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00003" summary="Add requirements.txt to control python package version">
|
||||
<option name="closed" value="true" />
|
||||
<created>1708267319084</created>
|
||||
<option name="number" value="00003" />
|
||||
<option name="presentableId" value="LOCAL-00003" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1708267319084</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="4" />
|
||||
<servers />
|
||||
</component>
|
||||
<component name="TypeScriptGeneratedFilesManager">
|
||||
<option name="version" value="3" />
|
||||
</component>
|
||||
<component name="Vcs.Log.Tabs.Properties">
|
||||
<option name="TAB_STATES">
|
||||
<map>
|
||||
<entry key="MAIN">
|
||||
<value>
|
||||
<State />
|
||||
</value>
|
||||
</entry>
|
||||
</map>
|
||||
</option>
|
||||
</component>
|
||||
<component name="VcsManagerConfiguration">
|
||||
<MESSAGE value="Initial code to get the weather data from the API" />
|
||||
<MESSAGE value="Add requirements.txt to control python package version" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="Add requirements.txt to control python package version" />
|
||||
</component>
|
||||
</project>
|
||||
20
Dockerfile
Normal file
20
Dockerfile
Normal file
@@ -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/
|
||||
10
main.py
10
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))
|
||||
|
||||
@@ -2,5 +2,4 @@ setuptools
|
||||
wheel
|
||||
requests
|
||||
datetime
|
||||
google-cloud-storage
|
||||
|
||||
|
||||
0
src/lambda_function/parse_to_dynamodb.py
Normal file
0
src/lambda_function/parse_to_dynamodb.py
Normal file
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user