From fd489d8de32c42651634d4bd25b3ee2472603369 Mon Sep 17 00:00:00 2001 From: Junior Date: Wed, 26 Jun 2024 11:06:39 -0400 Subject: [PATCH] A basic example for querying web/REST API data --- Python/050_apidata.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Python/050_apidata.py diff --git a/Python/050_apidata.py b/Python/050_apidata.py new file mode 100644 index 0000000..313a03e --- /dev/null +++ b/Python/050_apidata.py @@ -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']}") \ No newline at end of file