Open arashmehrabiparsa opened 8 months ago
`import requests import tkinter as tk import matplotlib.pyplot as plt import geopandas as gpd from shapely.geometry import Point from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
def get_iss_position(): response = requests.get(url="http://api.open-notify.org/iss-now.json") response.raise_for_status()
longitude_data = float(response.json()["iss_position"]["longitude"])
latitude_data = float(response.json()["iss_position"]["latitude"])
position = Point(longitude_data, latitude_data)
return gpd.GeoDataFrame(geometry=[position], crs="EPSG:4326")
def update_iss_position_on_map(): iss_position = get_iss_position()
# Clear previous map
ax.clear()
# Draw world map
world.plot(ax=ax, color='lightgray')
# Plot ISS position
iss_position.plot(ax=ax, marker='o', color='red', markersize=8, label='ISS Position')
# Update GUI
canvas.draw()
root.after(5000, update_iss_position_on_map) # Update every 5 seconds
root = tk.Tk() root.title("ISS Position Tracker")
world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
fig, ax = plt.subplots(figsize=(8, 6)) canvas = FigureCanvasTkAgg(fig, master=root) canvas.get_tk_widget().pack(side=tk.TOP, fill=tk.BOTH, expand=1)
update_iss_position_on_map()
root.mainloop() `
Test