"""
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
# RapidAPI page https://rapidapi.com/Coinranking/api/coinranking1/

# Begin Rapid API Code
import requests

url = "https://nba-schedule.p.rapidapi.com/schedule"

querystring = {"team":"GSW","date":"31-01-2022"}

headers = {
	"X-RapidAPI-Key": "4f0f5ee0b6msh1bcb7e2bb792a18p18c6b0jsn03bc958312b3",
	"X-RapidAPI-Host": "nba-schedule.p.rapidapi.com"
}

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

print(response.json())
# End Rapid API Code
json = response.json()  # convert response to python json object

# Observe data from an API.  This is how data transports over the internet in a "JSON" text form
# - The JSON "text" is formed in dictionary {} and list [] divisions
# - To read the result, Data Scientist of  Developer converts JSON into human readable form
# - Review the first line, look for the keys --  "status" and "data"
[{'gameDate': '1/31/2022 12:00:00 AM', 'games': [{'gameId': '0022100764', 'gameCode': '20220131/GSWHOU', 'gameStatus': 3, 'gameStatusText': 'Final', 'gameSequence': 7, 'gameDateEst': '2022-01-31T00:00:00Z', 'gameTimeEst': '1900-01-01T20:00:00Z', 'gameDateTimeEst': '2022-01-31T20:00:00Z', 'gameDateUTC': '2022-01-31T05:00:00Z', 'gameTimeUTC': '1900-01-02T01:00:00Z', 'gameDateTimeUTC': '2022-02-01T01:00:00Z', 'awayTeamTime': '2022-01-31T17:00:00Z', 'homeTeamTime': '2022-01-31T19:00:00Z', 'day': 'Mon', 'monthNum': 1, 'weekNumber': 16, 'weekName': 'Week 16', 'ifNecessary': False, 'seriesGameNumber': '', 'seriesText': '', 'arenaName': 'Toyota Center', 'arenaState': 'TX', 'arenaCity': 'Houston', 'postponedStatus': 'A', 'branchLink': 'https://app.link.nba.com/ZThbyrgCXib', 'broadcasters': {'nationalTvBroadcasters': [], 'nationalRadioBroadcasters': [], 'homeTvBroadcasters': [], 'homeRadioBroadcasters': [], 'awayTvBroadcasters': [], 'awayRadioBroadcasters': [], 'intlRadioBroadcasters': [], 'intlTvBroadcasters': []}, 'homeTeam': {'teamId': 1610612745, 'teamName': 'Rockets', 'teamCity': 'Houston', 'teamTricode': 'HOU', 'teamSlug': 'rockets', 'wins': 14, 'losses': 36, 'score': 108, 'seed': 0}, 'awayTeam': {'teamId': 1610612744, 'teamName': 'Warriors', 'teamCity': 'Golden State', 'teamTricode': 'GSW', 'teamSlug': 'warriors', 'wins': 38, 'losses': 13, 'score': 122, 'seed': 0}, 'pointsLeaders': [{'personId': 201939, 'firstName': 'Stephen', 'lastName': 'Curry', 'teamId': 1610612744, 'teamCity': 'Golden State', 'teamName': 'Warriors', 'teamTricode': 'GSW', 'points': 40}]}]}]