Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def astronauts():
- # 2. extract information from the website
- # 3. extract information from the reply received from the website - Dictionary
- # 4. Show the result to the user
- # 5. we should connect it back to the main menu
- window.clearscreen()
- # 1. set up the page
- window.bgpic('stars.gif')
- window.title('Astronauts in ISS')
- ISS = turtle.Turtle()
- ISS.penup()
- ISS.speed(0)
- ISS.hideturtle()
- ISS.color('orange')
- ISS.right(90)
- ISS.goto(-120, 50)
- ISS.write('The astronauts in the space are:',
- align='left', font=('Courier', 20, 'bold'))
- # http://api.open-notify.org/astros.json
- url = 'http://api.open-notify.org/astros.json'
- # AN API CALL
- # url ; requesting some information from that url -> response
- response = requests.get(url)
- # converting the response into data is imp
- # json is basically dictionary
- data = response.json()
- people_dict = data['people']
- astronauts = []
- for each in people_dict:
- print(each['name'])
- # how do i add this name, to the list astronauts?
- # easiest - beginner level
- astronauts = astronauts + [each['name']]
- # intermediate level
- # astronauts += [each['name']]
- # # advanced - experienced
- # astronauts.append(each['name'])
- print(astronauts)
- # names on the list astronauts
- # showing the user the names that we have
- ISS.color('white')
- ISS.forward(30)
- for name in astronauts:
- ISS.write(name, align='left', font=('Courier', 18, 'bold'))
- ISS.forward(15)
- # 1. Message for the user
- # 2. Action
- message()
- window.listen()
- window.onkey(main_menu, 'm')
- def message():
- message = turtle.Turtle()
- message.penup()
- message.hideturtle()
- message.color('red')
- message.sety(-87)
- message.write('Press M for Menu',
- align='center', font=('Courier', 15, 'bold'))
- # API Call?
- # Application Programming Interfact
- # API Call -> talk to a website for some information you may need from it
- def current_location():
- window.clearscreen()
- window.bgpic('Map.gif')
- window.title('Current Location of the ISS')
- ISS = turtle.Turtle()
- ISS.penup()
- ISS.speed(0)
- ISS.hideturtle()
- ISS.color('orange')
- ISS.right(90)
- ISS.sety(80)
- ISS.write('Current Location of the ISS:',
- align='center', font=('Courier', 15, 'bold'))
Advertisement
Add Comment
Please, Sign In to add comment