lecture added

This commit is contained in:
Edward Bigos 2025-11-25 08:47:47 -05:00
parent 34fea7f5da
commit e071375fdd
10 changed files with 10627 additions and 0 deletions

View file

@ -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'])

View file

@ -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)

View file

@ -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)

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

View file

@ -0,0 +1,6 @@
#!/bin/python3
import json
import turtle
import urllib.request

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 89 KiB

File diff suppressed because one or more lines are too long

View file

@ -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()