Python Worldtme API
Week 7 Hacks.
"""
Requests is a HTTP library for the Python programming language.
The goal of the project is to make HTTP requests simpler and more human-friendly.
"""
import requests
"""
RapidAPI is the world's largest API Marketplace.
Developers use Rapid API to discover and connect to thousands of APIs.
"""
url = "https://corona-virus-world-and-india-data.p.rapidapi.com/api"
headers = {
'x-rapidapi-key': "068e8e71ccmsh9b3b0cf234e3d0dp15d891jsn4e9a94382eba",
'x-rapidapi-host': "corona-virus-world-and-india-data.p.rapidapi.com"
}
# Request Covid Data
response = requests.request("GET", url, headers=headers)
# print(response.text) # uncomment this line to see raw data
# This code looks for "world data"
print("World Totals")
world = response.json().get('world_total') # turn response to json() so we can extract "world_total"
for key, value in world.items(): # this finds key, value pairs in country
print(key, value)
print()
# This code looks for USA in "countries_stats"
print("Country Totals")
countries = response.json().get('countries_stat')
for country in countries: # countries is a list
if country["country_name"] == "USA": # this filters for USA
for key, value in country.items(): # this finds key, value pairs in country
print(key, value)
import requests
url = "https://world-time2.p.rapidapi.com/timezone/Europe/London"
headers = {
"X-RapidAPI-Key": "c0f7469cd7mshc45a4834d55afdep1b5c00jsnc8a41fb46f94",
"X-RapidAPI-Host": "world-time2.p.rapidapi.com"
}
response = requests.request("GET", url, headers=headers)
parse_data = response.json()
datetime = parse_data["datetime"]
day_of_week = parse_data["day_of_week"]
day_of_year = parse_data["day_of_year"]
timezone = parse_data["timezone"]
utc_datetime = parse_data["utc_datetime"]
print("The time zone is: " + timezone)
print("This is the date and time: " + datetime)
print("What day of the week is it? " + str(day_of_week))
print("What day of the year is it? " + str(day_of_year))
print("This is the date and time in UTC: " + str(utc_datetime))