A basic example for querying web/REST API data
This commit is contained in:
parent
60848a24e3
commit
fd489d8de3
20
Python/050_apidata.py
Normal file
20
Python/050_apidata.py
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
# 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']}")
|
Loading…
Reference in New Issue
Block a user