"""
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

url = "https://corona-virus-world-and-india-data.p.rapidapi.com/api"

headers = {
	"X-RapidAPI-Key": "e819277188msh68a6f7af77fad4dp172d06jsnc2bc1f8ab152",
	"X-RapidAPI-Host": "corona-virus-world-and-india-data.p.rapidapi.com"
}

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


# print(response.text)

# 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://coinranking1.p.rapidapi.com/coins"
querystring = {"referenceCurrencyUuid":"yhjMzLPhuIDl","timePeriod":"24h","tiers[0]":"1","orderBy":"marketCap","orderDirection":"desc","limit":"50","offset":"0"}
headers = {
	"X-RapidAPI-Key": "jcmbea0fa2ff5msh7f14bf69be38ca6p175482jsn6c4988114560",  # place your key here
	"X-RapidAPI-Host": "coinranking1.p.rapidapi.com"
}

response = requests.request("GET", url, headers=headers, params=querystring)
print(response.text)
# 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"
{"message":"You are not subscribed to this API."}
"""
This cell is dependent on valid run of API above.
- try and except code is making sure "json" was properly run above
- inside second try is code that is used to process Coin API data

Note.  Run this cell repeatedly to format data without re-activating API
"""

try:
    print("JSON data is Python type: " + str(type(json)))
    try:
        # Extracting Coins JSON status, if the API worked
        status = json.get('status')
        print("API status: " + status)
        print()
        
        # Extracting Coins JSON data, data about the coins
        data = json.get('data')
        
        # Procedural abstraction of Print code for coins
        def print_coin(c):
            print(c["symbol"], c["price"])
            print("Icon Url: " + c["iconUrl"])
            print("Rank Url: " + c["coinrankingUrl"])

        # Coins data was observed to be a list
        for coin in data['coins']:
            print_coin(coin)
            print()
            
    except:
        print("Did you insert a valid key in X-RapidAPI-Key of API cell above?")
        print(json)
except:
    print("This cell is dependent on running API call in cell above!")
JSON data is Python type: <class 'dict'>
Did you insert a valid key in X-RapidAPI-Key of API cell above?
{'message': 'You are not subscribed to this API.'}
import requests
import json


url = "https://shazam.p.rapidapi.com/search"

querystring = {"term":"kiss the rain","locale":"en-US","offset":"0","limit":"5"}

headers = {
	"X-RapidAPI-Key": "e819277188msh68a6f7af77fad4dp172d06jsnc2bc1f8ab152",
	"X-RapidAPI-Host": "shazam.p.rapidapi.com"
}

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


print("Track_Name")
tracks = response.json().get('tracks')
hits = tracks.get('hits')
for track in hits:
	if track ["track"]['key'] == '40099833':
			json_formatted_str = json.dumps(track ["track"], indent=4)
			print (json_formatted_str)
Track_Name
{
    "layout": "5",
    "type": "MUSIC",
    "key": "40099833",
    "title": "Kiss The Rain",
    "subtitle": "Yiruma",
    "share": {
        "subject": "Kiss The Rain - Yiruma",
        "text": "I used Shazam to discover Kiss The Rain by Yiruma.",
        "href": "https://www.shazam.com/track/40099833/kiss-the-rain",
        "image": "https://is3-ssl.mzstatic.com/image/thumb/Music115/v4/0a/d1/e8/0ad1e89c-df29-a43e-9852-eb6ece2dd556/21UMGIM24785.rgb.jpg/400x400cc.jpg",
        "twitter": "I used @Shazam to discover Kiss The Rain by Yiruma.",
        "html": "https://www.shazam.com/snippets/email-share/40099833?lang=en-US&country=US",
        "avatar": "https://is4-ssl.mzstatic.com/image/thumb/Features115/v4/3f/84/4e/3f844e97-8c23-b64d-87f1-d536e99f80e9/mzl.rsxdpqqq.jpg/800x800cc.jpg",
        "snapchat": "https://www.shazam.com/partner/sc/track/40099833"
    },
    "images": {
        "background": "https://is4-ssl.mzstatic.com/image/thumb/Features115/v4/3f/84/4e/3f844e97-8c23-b64d-87f1-d536e99f80e9/mzl.rsxdpqqq.jpg/800x800cc.jpg",
        "coverart": "https://is3-ssl.mzstatic.com/image/thumb/Music115/v4/0a/d1/e8/0ad1e89c-df29-a43e-9852-eb6ece2dd556/21UMGIM24785.rgb.jpg/400x400cc.jpg",
        "coverarthq": "https://is3-ssl.mzstatic.com/image/thumb/Music115/v4/0a/d1/e8/0ad1e89c-df29-a43e-9852-eb6ece2dd556/21UMGIM24785.rgb.jpg/400x400cc.jpg",
        "joecolor": "b:0f1513p:f6f1ees:d7d6d1t:c7c5c2q:afafab"
    },
    "hub": {
        "type": "APPLEMUSIC",
        "image": "https://images.shazam.com/static/icons/hub/ios/v5/applemusic_{scalefactor}.png",
        "actions": [
            {
                "name": "apple",
                "type": "applemusicplay",
                "id": "1576663126"
            },
            {
                "name": "apple",
                "type": "uri",
                "uri": "https://audio-ssl.itunes.apple.com/itunes-assets/AudioPreview112/v4/b5/71/fd/b571fdea-62b9-64e8-1531-3d845cf6ee58/mzaf_8999534599011571502.plus.aac.ep.m4a"
            }
        ],
        "options": [
            {
                "caption": "OPEN",
                "actions": [
                    {
                        "name": "hub:applemusic:deeplink",
                        "type": "applemusicopen",
                        "uri": "https://music.apple.com/us/album/kiss-the-rain/1576662868?i=1576663126&mttnagencyid=s2n&mttnsiteid=125115&mttn3pid=Apple-Shazam&mttnsub1=Shazam_ios&mttnsub2=5348615A-616D-3235-3830-44754D6D5973&itscg=30201&app=music&itsct=Shazam_ios"
                    },
                    {
                        "name": "hub:applemusic:deeplink",
                        "type": "uri",
                        "uri": "https://music.apple.com/us/album/kiss-the-rain/1576662868?i=1576663126&mttnagencyid=s2n&mttnsiteid=125115&mttn3pid=Apple-Shazam&mttnsub1=Shazam_ios&mttnsub2=5348615A-616D-3235-3830-44754D6D5973&itscg=30201&app=music&itsct=Shazam_ios"
                    }
                ],
                "beacondata": {
                    "type": "open",
                    "providername": "applemusic"
                },
                "image": "https://images.shazam.com/static/icons/hub/ios/v5/overflow-open-option_{scalefactor}.png",
                "type": "open",
                "listcaption": "Open in Apple Music",
                "overflowimage": "https://images.shazam.com/static/icons/hub/ios/v5/applemusic-overflow_{scalefactor}.png",
                "colouroverflowimage": false,
                "providername": "applemusic"
            },
            {
                "caption": "BUY",
                "actions": [
                    {
                        "type": "uri",
                        "uri": "https://itunes.apple.com/us/album/kiss-the-rain/1576662868?i=1576663126&mttnagencyid=s2n&mttnsiteid=125115&mttn3pid=Apple-Shazam&mttnsub1=Shazam_ios&mttnsub2=5348615A-616D-3235-3830-44754D6D5973&itscg=30201&app=itunes&itsct=Shazam_ios"
                    }
                ],
                "beacondata": {
                    "type": "buy",
                    "providername": "itunes"
                },
                "image": "https://images.shazam.com/static/icons/hub/ios/v5/itunes-overflow-buy_{scalefactor}.png",
                "type": "buy",
                "listcaption": "Buy on iTunes",
                "overflowimage": "https://images.shazam.com/static/icons/hub/ios/v5/itunes-overflow-buy_{scalefactor}.png",
                "colouroverflowimage": false,
                "providername": "itunes"
            }
        ],
        "providers": [
            {
                "caption": "Open in Spotify",
                "images": {
                    "overflow": "https://images.shazam.com/static/icons/hub/ios/v5/spotify-overflow_{scalefactor}.png",
                    "default": "https://images.shazam.com/static/icons/hub/ios/v5/spotify_{scalefactor}.png"
                },
                "actions": [
                    {
                        "name": "hub:spotify:searchdeeplink",
                        "type": "uri",
                        "uri": "spotify:search:Kiss%20The%20Rain%20Yiruma"
                    }
                ],
                "type": "SPOTIFY"
            },
            {
                "caption": "Open in Deezer",
                "images": {
                    "overflow": "https://images.shazam.com/static/icons/hub/ios/v5/deezer-overflow_{scalefactor}.png",
                    "default": "https://images.shazam.com/static/icons/hub/ios/v5/deezer_{scalefactor}.png"
                },
                "actions": [
                    {
                        "name": "hub:deezer:searchdeeplink",
                        "type": "uri",
                        "uri": "deezer-query://www.deezer.com/play?query=%7Btrack%3A%27Kiss+The+Rain%27%20artist%3A%27Yiruma%27%7D"
                    }
                ],
                "type": "DEEZER"
            }
        ],
        "explicit": false,
        "displayname": "APPLE MUSIC"
    },
    "artists": [
        {
            "id": "42",
            "adamid": "73406786"
        }
    ],
    "url": "https://www.shazam.com/track/40099833/kiss-the-rain"
}