
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)
