diff --git a/bigos/lecture20251125/urllib/chuck-norris-db.py b/bigos/lecture20251125/urllib/chuck-norris-db.py new file mode 100644 index 0000000..cc1ed90 --- /dev/null +++ b/bigos/lecture20251125/urllib/chuck-norris-db.py @@ -0,0 +1,29 @@ +import json +import urllib.request +import pprint + +# See https://www.icndb.com + +def get_joke(): + + url = "https://api.chucknorris.io/jokes/random?limitTo=nerdy " + + response = urllib.request.urlopen(url) + result = json.loads(response.read()) + +# print(result) + + return result + +def prettyPrintDictionary(myDict): + pprint.pprint(myDict) + + + +joke = get_joke() + +prettyPrintDictionary(joke) + +print(joke['value']) + + diff --git a/bigos/lecture20251125/urllib/iss/iss-4.py b/bigos/lecture20251125/urllib/iss/iss-4.py new file mode 100644 index 0000000..e7d652d --- /dev/null +++ b/bigos/lecture20251125/urllib/iss/iss-4.py @@ -0,0 +1,55 @@ + +import json +import urllib.request +import turtle + +import time + +url = 'http://api.open-notify.org/astros.json' +response = urllib.request.urlopen(url) +result = json.loads(response.read()) + +print(result) + +print("People on the ISS: ",result['number']) +people = result['people'] +#print(people) + +#for person in people: +# print(person) + +for person in people : + print(person['name']) + + +url = 'http://api.open-notify.org/iss-now.json' +response = urllib.request.urlopen(url) +result = json.loads(response.read()) + +print(result) + +location = result['iss_position'] +latitude = location['latitude'] +longitude = location['longitude'] + +print('Latitude: ',latitude) +print('Longitude: ',longitude) + +screen = turtle.Screen() + +screen.setup(720,360) +screen.setworldcoordinates(-180,-90,180,90) +screen.bgpic('map.gif') + + +screen.register_shape('iss.gif') +iss = turtle.Turtle() +iss.shape('iss.gif') +iss.setheading(90) + +iss.penup() +iss.goto(float(longitude),float(latitude) ) + +# Print the map + +time.sleep(15) diff --git a/bigos/lecture20251125/urllib/iss/iss-4a.py b/bigos/lecture20251125/urllib/iss/iss-4a.py new file mode 100644 index 0000000..03f0250 --- /dev/null +++ b/bigos/lecture20251125/urllib/iss/iss-4a.py @@ -0,0 +1,78 @@ + +import json +import urllib.request +import turtle +import pprint + +import time + +debugFlag = True +debugFlag = False + +url = 'http://api.open-notify.org/astros.json' +response = urllib.request.urlopen(url) +result = json.loads(response.read()) + +if debugFlag: + pp = pprint.PrettyPrinter(indent=4) + pp.pprint(result) + time.sleep(10) + +people = result['people'] +ISSpeople = [] +Tiangongpeople = [] + +for person in people: + if person['craft'] == 'ISS': + ISSpeople.append(person['name']) + else: + Tiangongpeople.append(person['name']) + +if debugFlag: + pp = pprint.PrettyPrinter(indent=4) + print("ISSpeople") + pp.pprint(ISSpeople) + print("Tiangongpeople") + pp.pprint(Tiangongpeople) + time.sleep(10) + +print("People on the ISS: ",len(ISSpeople)) +for person in ISSpeople : + print(f"\t{person}") + +print("People on the Tiangong: ",len(Tiangongpeople)) +for person in Tiangongpeople : + print(f"\t{person}") + + +url = 'http://api.open-notify.org/iss-now.json' +response = urllib.request.urlopen(url) +result = json.loads(response.read()) + +print(result) + +location = result['iss_position'] +latitude = location['latitude'] +longitude = location['longitude'] + +print('Latitude: ',latitude) +print('Longitude: ',longitude) + +screen = turtle.Screen() + +screen.setup(720,360) +screen.setworldcoordinates(-180,-90,180,90) +screen.bgpic('map.gif') + + +screen.register_shape('iss.gif') +iss = turtle.Turtle() +iss.shape('iss.gif') +iss.setheading(90) + +iss.penup() +iss.goto(float(longitude),float(latitude) ) + +# Print the map + +time.sleep(15) diff --git a/bigos/lecture20251125/urllib/iss/iss-project-resources.zip b/bigos/lecture20251125/urllib/iss/iss-project-resources.zip new file mode 100644 index 0000000..ba32cf1 Binary files /dev/null and b/bigos/lecture20251125/urllib/iss/iss-project-resources.zip differ diff --git a/bigos/lecture20251125/urllib/iss/iss.gif b/bigos/lecture20251125/urllib/iss/iss.gif new file mode 100644 index 0000000..b879e3e Binary files /dev/null and b/bigos/lecture20251125/urllib/iss/iss.gif differ diff --git a/bigos/lecture20251125/urllib/iss/iss.py b/bigos/lecture20251125/urllib/iss/iss.py new file mode 100644 index 0000000..99be33e --- /dev/null +++ b/bigos/lecture20251125/urllib/iss/iss.py @@ -0,0 +1,6 @@ +#!/bin/python3 + +import json +import turtle +import urllib.request + diff --git a/bigos/lecture20251125/urllib/iss/iss2.gif b/bigos/lecture20251125/urllib/iss/iss2.gif new file mode 100644 index 0000000..9fb8885 Binary files /dev/null and b/bigos/lecture20251125/urllib/iss/iss2.gif differ diff --git a/bigos/lecture20251125/urllib/iss/map.gif b/bigos/lecture20251125/urllib/iss/map.gif new file mode 100644 index 0000000..f798263 Binary files /dev/null and b/bigos/lecture20251125/urllib/iss/map.gif differ diff --git a/bigos/lecture20251125/urllib/iss/result.html b/bigos/lecture20251125/urllib/iss/result.html new file mode 100644 index 0000000..65aaafd --- /dev/null +++ b/bigos/lecture20251125/urllib/iss/result.html @@ -0,0 +1,10415 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/bigos/lecture20251125/urllib/plot_football.py b/bigos/lecture20251125/urllib/plot_football.py new file mode 100644 index 0000000..f6397f0 --- /dev/null +++ b/bigos/lecture20251125/urllib/plot_football.py @@ -0,0 +1,44 @@ +""" +======== +Football +======== + +Load football network in GML format and compute some network statistcs. + +Shows how to download GML graph in a zipped file, unpack it, and load +into a NetworkX graph. + +Requires Internet connection to download the URL +http://www-personal.umich.edu/~mejn/netdata/football.zip +""" + +import urllib.request +import io +import zipfile + +import matplotlib.pyplot as plt +import networkx as nx + +url = "http://www-personal.umich.edu/~mejn/netdata/football.zip" + +sock = urllib.request.urlopen(url) # open URL +s = io.BytesIO(sock.read()) # read into BytesIO "file" +sock.close() + +zf = zipfile.ZipFile(s) # zipfile object +txt = zf.read("football.txt").decode() # read info file +gml = zf.read("football.gml").decode() # read gml data +# throw away bogus first line with # from mejn files +gml = gml.split("\n")[1:] +G = nx.parse_gml(gml) # parse gml data + +print(txt) +# print degree for each team - number of games +for n, d in G.degree(): + print(f"{n:20} {d:2}") + +options = {"node_color": "black", "node_size": 50, "linewidths": 0, "width": 0.1} + +pos = nx.spring_layout(G, seed=1969) # Seed for reproducible layout +nx.draw(G, pos, **options) +plt.show()