back home

API query and processing



Ten wisdoms


(1)
(2)
(3)
(4)
(5)
(6)
(7)
(8)
(9)
(10)
# import pandas as pd # import sqlite3 as sql import json from pyodide.http import open_url # from io import StringIO # read url source_url = [] url_content = [] urldata = [] urldict = [] source_url.append('https://api.agify.io/?name=ralf') source_url.append('https://api.agify.io/?name=simone') source_url.append('https://api2.binance.com/api/v3/ticker/24hr') source_url.append('https://www.boredapi.com/api/activity') source_url.append('https://open.er-api.com/v6/latest/EUR') source_url.append('https://api.ipify.org/?format=json') source_url.append('https://v2.jokeapi.dev/joke/Any?safe-mode') source_url.append('https://goweather.herokuapp.com/weather/cairo') source_url.append('https://random-words-api.vercel.app/word') source_url.append('https://api.sunrise-sunset.org/json?lat=30.04243510169307&lng=31.47671653030487') for url_to_fetch in source_url: url_content.append(open_url(url_to_fetch)) for data_to_fetch in url_content: urldata.append(data_to_fetch.getvalue()) for dict_to_fetch in urldata: urldict.append(json.loads(dict_to_fetch)) outspace1 = Element('outspace1') outspace1.write(str(urldict[0]['count']) + ' ' + urldict[0]['name'] + 's are in average ' + str(urldict[0]['age']) + ' years old.') outspace2 = Element('outspace2') outspace2.write(str(urldict[1]['count']) + ' ' + urldict[1]['name'] + 's are in average ' + str(urldict[1]['age']) + ' years old.') outspace3 = Element('outspace3') outspace3.write(str(urldict[2][11]['symbol']) + ' costs ' + str(urldict[2][11]['weightedAvgPrice']) + ' USD') outspace4 = Element('outspace4') outspace4.write(str(urldict[3]['activity'])) outspace5 = Element('outspace5') outspace5.write('Value of EUR: ' + str(urldict[4]['rates']['EGP']) + ' EGP ' + str(urldict[4]['rates']['USD']) + ' USD') outspace6 = Element('outspace6') outspace6.write('IP adress: ' + str(urldict[5]['ip'])) outspace7 = Element('outspace7') if urldict[6]['type'] == 'single': outspace7.write(urldict[6]['joke']) elif urldict[6]['type'] == 'twopart': outspace7.write(urldict[6]['setup'] + ' --- ' + urldict[6]['delivery']) outspace8 = Element('outspace8') outspace8.write('Cairo weather: ' + urldict[7]['description'] + '/' + urldict[7]['temperature'] + '/' + urldict[7]['wind'] + \ ' becoming ' + urldict[7]['forecast'][0]['temperature'] + '/' + urldict[7]['forecast'][0]['wind']) outspace9 = Element('outspace9') outspace9.write(urldict[8][0]['word'] + '=' + urldict[8][0]['definition']) outspace10 = Element('outspace10') outspace10.write('Sun is up in Cairo from ' + urldict[9]['results']['sunrise'] + ' to ' + urldict[9]['results']['sunset'] + ' UTC.')