Last active
June 13, 2024 16:24
-
-
Save mike-weiner/1f6d9dc424b2ad684e56b3af6866e82f to your computer and use it in GitHub Desktop.
A Python script to serve as a template for WeatherLink API calls using the newer authentication method.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import requests | |
# API v2 Base URL | |
BASE_URL = "https://api.weatherlink.com/v2/" | |
# Your WeatherLink Account API Credentials | |
API_KEY = "<your-api-key>" | |
API_SECRET = "<your-api-secret>" | |
# API v2 Endpoint URL | |
# https://weatherlink.github.io/v2-api/api-reference | |
endpoint = "stations" | |
# API Path Parameters | |
# Add the necessary _path_ parameters necessary for the API endpoint that you are querying | |
pathParameters = [ | |
] | |
# API Query String Parameters | |
# Add the necessary _query string_ parameters necessary for the API endpoint that you are querying | |
queryParameters = [ | |
] | |
# Create final API URL | |
api_url = BASE_URL + endpoint | |
api_url += ''.join("/" + str(param) for param in pathParameters)[0:] | |
api_url += "?api-key=" + API_KEY | |
api_url += ''.join("&" + str(x) + "=" + str(y) for (x,y) in queryParameters)[0:] | |
# Make call to API and pretty-print returned data | |
api_results = requests.get( | |
headers= { | |
"X-Api-Secret": API_SECRET | |
}, | |
url=api_url, | |
verify=True, | |
) | |
print(json.dumps(json.loads(api_results.text), indent=4)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The "older" signature authentication method is still supported. A template script for that authentication method is found here: https://gist.github.com/mike-weiner/3ea4654ccfec57234c0520e773f78225