Data Navigation Bar Covid19 API Love Calculator API

Notes

  • RapidAPI, you will select Python Requests type of code to work with your Notebook
  • The url is the endpoint to which the API is directed
  • The headers is a dictionary data structure to send special messaging to the endpoint
  • The requests.request() python function is used to send a request and retrieve their responses
  • The response variable receives result of of the request in JSON text
  • Replace key with personal key to access the API
  • Remember to subscribe to the API to access

My Process

I explored the RapidAPI a ton, and I played around with many of the APIs. I found a ton of practical ones, as well as fun ones, and I have our group's final project in mind when I search through the APIs. There are a lot that I found that we could potentially utilize, such as a gratitude message generator, a mood tracker, and mental health stats. Those are some practical ones, but this fun one below was my favorite that I tried out.

Covid19 RapidAPI 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': "dec069b877msh0d9d0827664078cp1a18fajsn2afac35ae063",
    '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

Love Calculator API

import requests

url = "https://love-calculator.p.rapidapi.com/getPercentage"

querystring = {"sname":"Annika Liao","fname":"Alex Turner"}

headers = {
	"X-RapidAPI-Key": "26fd9549c8msh64e7e2f5ac3301fp18259djsn17ca48c66a6a",
	"X-RapidAPI-Host": "love-calculator.p.rapidapi.com"
}

response = requests.request("GET", url, headers=headers, params=querystring)

print(response.text)
{"fname":"Alex Turner","sname":"Annika Liao","percentage":"99","result":"Congratulations! Good choice"}