Coronavirus API example

"""
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)
World Totals
total_cases 509,268,964
new_cases 204,268
total_deaths 6,242,509
new_deaths 630
total_recovered 461,827,849
active_cases 41,198,606
serious_critical 42,510
total_cases_per_1m_population 65,334
deaths_per_1m_population 800.9
statistic_taken_at 2022-04-24 11:18:01

Country Totals
country_name USA
cases 82,649,779
deaths 1,018,316
region 
total_recovered 80,434,925
new_deaths 0
new_cases 0
serious_critical 1,465
active_cases 1,196,538
total_cases_per_1m_population 247,080
deaths_per_1m_population 3,044
total_tests 1,000,275,726
tests_per_1m_population 2,990,303

Group Project Worldtime API

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))
The time zone is: Europe/London
This is the date and time: 2022-10-14T17:43:48.375157+01:00
What day of the week is it? 5
What day of the year is it? 287
This is the date and time in UTC: 2022-10-14T16:43:48.375157+00:00