z3xt5r

Untitled

Feb 19th, 2021
708
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.48 KB | None | 0 0
  1.  
  2. def astronauts():
  3.  
  4.     # 2. extract information from the website
  5.     # 3. extract information from the reply received from the website - Dictionary
  6.     # 4. Show the result to the user
  7.     # 5. we should connect it back to the main menu
  8.     window.clearscreen()
  9.     # 1. set up the page
  10.     window.bgpic('stars.gif')
  11.     window.title('Astronauts in ISS')
  12.     ISS = turtle.Turtle()
  13.     ISS.penup()
  14.     ISS.speed(0)
  15.     ISS.hideturtle()
  16.     ISS.color('orange')
  17.     ISS.right(90)
  18.     ISS.goto(-120, 50)
  19.     ISS.write('The astronauts in the space are:',
  20.               align='left', font=('Courier', 20, 'bold'))
  21.     # http://api.open-notify.org/astros.json
  22.     url = 'http://api.open-notify.org/astros.json'
  23.  
  24.     # AN API CALL
  25.     # url ; requesting some information from that url -> response
  26.  
  27.     response = requests.get(url)
  28.     # converting the response into data is imp
  29.     # json is basically dictionary
  30.     data = response.json()
  31.  
  32.     people_dict = data['people']
  33.     astronauts = []
  34.     for each in people_dict:
  35.         print(each['name'])
  36.         # how do i add this name, to the list astronauts?
  37.         # easiest - beginner level
  38.         astronauts = astronauts + [each['name']]
  39.         # intermediate level
  40.         # astronauts += [each['name']]
  41.         # # advanced - experienced
  42.         # astronauts.append(each['name'])
  43.     print(astronauts)
  44.  
  45.     # names on the list astronauts
  46.     # showing the user the names that we have
  47.  
  48.     ISS.color('white')
  49.     ISS.forward(30)
  50.     for name in astronauts:
  51.         ISS.write(name, align='left', font=('Courier', 18, 'bold'))
  52.         ISS.forward(15)
  53.  
  54.     # 1. Message for the user
  55.     # 2. Action
  56.     message()
  57.     window.listen()
  58.     window.onkey(main_menu, 'm')
  59.  
  60.  
  61. def message():
  62.     message = turtle.Turtle()
  63.     message.penup()
  64.     message.hideturtle()
  65.     message.color('red')
  66.     message.sety(-87)
  67.     message.write('Press M for Menu',
  68.                   align='center', font=('Courier', 15, 'bold'))
  69.  
  70. # API Call?
  71. # Application Programming Interfact
  72. # API Call -> talk to a website for some information you may need from it
  73.  
  74.  
  75. def current_location():
  76.     window.clearscreen()
  77.     window.bgpic('Map.gif')
  78.     window.title('Current Location of the ISS')
  79.     ISS = turtle.Turtle()
  80.     ISS.penup()
  81.     ISS.speed(0)
  82.     ISS.hideturtle()
  83.     ISS.color('orange')
  84.     ISS.right(90)
  85.     ISS.sety(80)
  86.     ISS.write('Current Location of the ISS:',
  87.               align='center', font=('Courier', 15, 'bold'))
  88.  
  89.  
  90.  
Advertisement
Add Comment
Please, Sign In to add comment