![]() |
VOOZH | about |
In this article, we will discuss how to track the current location of ISS(International Space Station) and then maps the location. We will write a script that will display the current location of ISS along with onboarded crew names. It works on API, it takes the current location of ISS in the form of latitude and longitude and then locates that value onto the map. It takes the value from the website at every 5 sec and then updates the value of latitude and longitude and thus also moves the ISS icon on the world map. The movement visible is very little but you can notice that movement in the gif below. This is possible by using some of the modules of python like JSON, urllib.requests, Webbrowser, Geocoder etc. Numerous functions are used to create this script.
pip install jsonlib
pip install turtle
pip install urllib3
pip install times
pip install pycopy-webbrowser
pip install geocoder
So now there is a problem with tracking ISS because it travels at a speed of almost 28000km/h. Thus, it takes only 90 minutes to complete 1 rotation around the earth. At such a speed, it becomes quite difficult to lock the exact coordinates. So here comes the API to solve this issue. API acts as an intermediate between the website and the program, thus providing the current time data for the program.
In our case, API will provide us with the current location of ISS in earth's orbit, so visit the link below as an API link for astronaut info.
url = "http://api.open-notify.org/astros.json"
Use urllib.request.urlopen() function inorder to open the API url and json.loads(.read()) function to read the data from the url.
Output:
{'people': [{'name': 'Mark Vande Hei', 'craft': 'ISS'},
{'name': 'Oleg Novitskiy', 'craft': 'ISS'},
{'name': 'Pyotr Dubrov', 'craft': 'ISS'},
{'name': 'Thomas Pesquet', 'craft': 'ISS'},
{'name': 'Megan McArthur', 'craft': 'ISS'},
{'name': 'Shane Kimbrough', 'craft': 'ISS'},
{'name': 'Akihiko Hoshide', 'craft': 'ISS'},
{'name': 'Nie Haisheng', 'craft': 'Tiangong'},
{'name': 'Liu Boming', 'craft': 'Tiangong'},
{'name': 'Tang Hongbo', 'craft': 'Tiangong'}],
'number': 10,
'message': 'success'}
Create.txt file for astronauts info: Create iss.text file using an open() function in write mode and write the result(names & numbers of astronauts) as data inside the file.
Use geocoder.ip('me') to know your current location in terms of latitude and longitude and after that using write the data in the file and then close the file using the file.close() function.
Use turtle.screen() function to get access to the screen, then use screen.setup() to set the size and position of the output window. Use screen.setworldcoordinates() function to set the coordinates of all 4 corners on x, y-axis so that when iss reach out from reaches they appear again from another edge.
Set map as background pic using screen.bgpic() function and set iss image as turtle shape using screen.register_shape() function. Use it as an object and assign it as a shape using iss.shape() function, then set the angle of shape using iss.setheading() function. iss.penup() function indicates that their drawings. Thus, the turtle stops.
The file can be downloaded:
Code:
Access the current status of ISS using the API below:
url = "http://api.open-notify.org/iss-now.json"
Extract the current location of ISS in terms of latitude and longitude from the above API. This script below runs inside the while loop so you can see the updated position and movement of the ISS until you stop the program.
Update the position of ISS every 5 seconds by refreshing the latitude and longitude value from API.
Below is the full implementation.
Output:
Crew Information: Here is info on the onboarded crew members along with their names.
ISS Location: Here is a screenshot of the moving ISS i.e orbiting around the earth. You can see it by zooming in on the screenshot.
ISS Moving look: Here you can see the ISS moving every 5 seconds.