-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathexample.py
More file actions
38 lines (38 loc) · 1.22 KB
/
example.py
File metadata and controls
38 lines (38 loc) · 1.22 KB
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
# This is an example for StepZen weather API
import os
import sys
import requests
# Please set your StepZen access key here
access_key = "Your StepZen access key"
# Please set the URL for the StepZen weather API endpoint
url = "https://api.stepzen.com/v1/weather"
# Please set the latitude and longitude for the location
# for which you want to get the weather information
latitude = "37.386"
longitude = "-122.08"
# Please set the start date and end date for which you want to get the weather information
start_date = "2019-01-01"
end_date = "2019-01-31"
# Please set the units for the weather information
units = "m"
# Set the headers for the HTTP request
headers = {
"Content-Type": "application/json",
"X-Api-Key": access_key
}
# Set the parameters for the HTTP request
params = {
"latitude": latitude,
"longitude": longitude,
"startDate": start_date,
"endDate": end_date,
"units": units
}
# Execute the HTTP request
response = requests.get(url, headers=headers, params=params)
# Check for HTTP codes other than 200
if response.status_code != 200:
print("HTTP error: {} - {}".format(response.status_code, response.text))
sys.exit(1)
# Print the response from the StepZen weather API
print(response.json())