BigSteve/Python/050_apidata.py

20 lines
865 B
Python

# Retrieving data from a Web/REST API
# Import the library for web requests
import requests
# The URL of our API call
URL = "https://jackpot.jaj.com/weather/"
# Make the request for data
response = requests.get(URL)
# response.json() will contain the json data returned from the request.
# This data can be accessed just like a dictionary/dict.
# Load the URL above in Firefox or Edge to see the available data fields
print("Current Weather in Beavercreek, OH")
print(f" Conditions: {response.json()['current']['weather'][0]['main']}")
print(f" Temperature: {response.json()['current']['temp']}° F (feels like {response.json()['current']['feels_like']}° F)")
print(f" Humidity: {response.json()['current']['humidity']}%")
print(f" Wind: {response.json()['current']['wind_speed']} MPH")
print(f" Prediction: {response.json()['daily'][0]['summary']}")