lecture added
This commit is contained in:
parent
34fea7f5da
commit
e071375fdd
10 changed files with 10627 additions and 0 deletions
29
bigos/lecture20251125/urllib/chuck-norris-db.py
Normal file
29
bigos/lecture20251125/urllib/chuck-norris-db.py
Normal 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'])
|
||||||
|
|
||||||
|
|
||||||
55
bigos/lecture20251125/urllib/iss/iss-4.py
Normal file
55
bigos/lecture20251125/urllib/iss/iss-4.py
Normal 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)
|
||||||
78
bigos/lecture20251125/urllib/iss/iss-4a.py
Normal file
78
bigos/lecture20251125/urllib/iss/iss-4a.py
Normal 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)
|
||||||
BIN
bigos/lecture20251125/urllib/iss/iss-project-resources.zip
Normal file
BIN
bigos/lecture20251125/urllib/iss/iss-project-resources.zip
Normal file
Binary file not shown.
BIN
bigos/lecture20251125/urllib/iss/iss.gif
Normal file
BIN
bigos/lecture20251125/urllib/iss/iss.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.5 KiB |
6
bigos/lecture20251125/urllib/iss/iss.py
Normal file
6
bigos/lecture20251125/urllib/iss/iss.py
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
#!/bin/python3
|
||||||
|
|
||||||
|
import json
|
||||||
|
import turtle
|
||||||
|
import urllib.request
|
||||||
|
|
||||||
BIN
bigos/lecture20251125/urllib/iss/iss2.gif
Normal file
BIN
bigos/lecture20251125/urllib/iss/iss2.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.4 KiB |
BIN
bigos/lecture20251125/urllib/iss/map.gif
Normal file
BIN
bigos/lecture20251125/urllib/iss/map.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 89 KiB |
10415
bigos/lecture20251125/urllib/iss/result.html
Normal file
10415
bigos/lecture20251125/urllib/iss/result.html
Normal file
File diff suppressed because one or more lines are too long
44
bigos/lecture20251125/urllib/plot_football.py
Normal file
44
bigos/lecture20251125/urllib/plot_football.py
Normal 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()
|
||||||
Loading…
Add table
Add a link
Reference in a new issue