PYTHON   62

Pastebin raw data ydjtxsx4

Guest on 23rd July 2021 09:13:40 AM

  1. import turtle
  2. import json
  3. import requests
  4.  
  5. '''
  6. 1. Importing libraries
  7. 2. Creating the window
  8. 4 pages in total
  9. - Astronauts
  10. - Current Location
  11. - Tracking
  12. - Exit
  13. All 4 pages will have a separate function
  14. - Heading
  15. - Background
  16. - Title
  17. - Contents
  18. '''
  19.  
  20.  
  21. def main_menu():
  22.     window.title('ISS App')
  23.     window.bgpic('stars.gif')
  24.  
  25.     menu = turtle.Turtle()
  26.     menu.penup()
  27.     menu.hideturtle()
  28.     menu.color('orange')
  29.  
  30.     menu.sety(65)
  31.     menu.write('~~~Explore Space with Anish~~~', align='center',
  32.                font=('Courier', 24, 'bold'))
  33.     menu.right(90)
  34.     menu.goto(-120, 20)
  35.     menu.color('white')
  36.  
  37.     menu.write('a. Astronauts in Space', align='left',
  38.                font=('Courier', 20, 'bold'))
  39.     menu.forward(25)
  40.     menu.write('b. Current Location', align='left',
  41.                font=('Courier', 20, 'bold'))
  42.     menu.forward(25)
  43.     menu.write('c. Tracking the ISS', align='left',
  44.                font=('Courier', 20, 'bold'))
  45.     menu.forward(25)
  46.     menu.write('d. Exit', align='left',
  47.                font=('Courier', 20, 'bold'))
  48.  
  49.     window.listen()
  50.     window.onkey(astronauts, 'a')
  51.  
  52.  
  53. def astronauts():
  54.     window.clearscreen()
  55.     window.title('Astronauts in ISS')
  56.     window.bgpic('stars.gif')
  57.  
  58.     ISS = turtle.Turtle()
  59.     ISS.penup()
  60.     ISS.hideturtle()
  61.     ISS.color('orange')
  62.  
  63.     ISS.sety(65)
  64.     ISS.write('Astronauts in ISS', align='center',
  65.               font=('Courier', 24, 'bold'))
  66.     ISS.right(90)
  67.  
  68.     # API Calling
  69.     url = 'http://api.open-notify.org/astros.json'
  70.     response = requests.get(url)
  71.     print(response)
  72.     data = response.json()
  73.     # print(json.dumps(data, indent=4))
  74.     names = []
  75.     for i in data['people']:
  76.         if i['craft'] == 'ISS':
  77.             # print(i['name'])
  78.             names.append(i['name'])
  79.     ISS.color('white')
  80.     ISS.goto(-90, 35)
  81.     for name in names:
  82.         ISS.write(name, align='left', font=('Calibri', 20, 'bold'))
  83.         ISS.forward(20)
  84.  
  85.  
  86. window = turtle.Screen()
  87. window.setup(720, 360)
  88. window.setworldcoordinates(-180, -90, 180, 90)
  89. main_menu()
  90.  
  91. while True:
  92.     window.update()

Raw Paste


Login or Register to edit or fork this paste. It's free.