-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaccuweather_api.py
35 lines (25 loc) · 1002 Bytes
/
accuweather_api.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
# Call to Open Weather API to retrieve forecast data for Wild Pansy Farm
import requests
import pandas as pd
from datetime import datetime, timedelta
import config
import boto3
import json
# OpenWeather API call
def api_call(endpoint):
response = requests.get(endpoint)
json_data = response.json()
return json_data
# Wild Pansy Farm veggie field zip code
zip_code = "47229"
forecast_endpoint = "http://dataservice.accuweather.com/currentconditions/v1/" + zip_code + "/historical/24?apikey=" + config.accuweather_app_key + "&details=true"
inbound_message = api_call(forecast_endpoint)
# Create file with the data
with open('aw_data.txt', 'w') as outfile:
json.dump(inbound_message, outfile)
# Save inbound data to S3 with timestamped_standard_name.json (?)
file_date = datetime.now().strftime("%Y%m%d-%H%M")
filename = file_date + '_' + 'awdata.txt'
s3 = boto3.resource('s3')
BUCKET = 'wpf-weather-data'
s3.Bucket(BUCKET).upload_file('aw_data.txt', "weather-data/" + filename)