type hints

This commit is contained in:
Felix Pankratz 2025-07-21 11:09:18 +02:00
parent 4e6ff22dba
commit 037ce01efd

View File

@ -1,6 +1,6 @@
#!/usr/bin/env python3
from kitty import draw_to_terminal, get_position, set_position, hide_cursor, show_cursor
import kitty
import pyvista as pv
import numpy as np
@ -17,7 +17,7 @@ from io import BytesIO
# Convert lat/lon to Cartesian coordinates
def latlon_to_xyz(lat, lon, radius=1.0):
def latlon_to_xyz(lat: float, lon: float, radius=1.0):
lat_rad = np.radians(lat)
lon_rad = np.radians(lon)
x = radius * np.cos(lat_rad) * np.cos(lon_rad)
@ -53,19 +53,19 @@ def generate_arch(p1, p2, height_factor=0.2, n_points=100):
return arch_points
def traceroute(target):
def traceroute(target: str) -> list[tuple[int, int]]:
# Run traceroute command
result = subprocess.run(
["traceroute", "-n", target, "-q", "1", "-w", "1,3,10"],
capture_output=True,
text=True,
)
hops = re.findall(r"\n\s*\d+\s+([\d.]+)", result.stdout)
hops: list[str] = re.findall(r"\n\s*\d+\s+([\d.]+)", result.stdout)
coords = []
coords: list[tuple[int,int]] = []
for ip in hops:
try:
response = requests.get(f"http://ip-api.com/json/{ip}").json()
response: dict = requests.get(f"http://ip-api.com/json/{ip}").json()
if response["status"] == "success":
coords.append((response["lat"], response["lon"]))
except Exception:
@ -110,7 +110,7 @@ def main():
# Convert to 3D coordinates
points_3d = [latlon_to_xyz(lat, lon) for lat, lon in locations]
pl = pv.Plotter(off_screen=(not args.external))
pl : pv.Plotter = pv.Plotter(off_screen=(not args.external))
pl.add_mesh(globe, color="tan", smooth_shading=True, texture=tex, show_edges=False)
for pt in points_3d:
@ -121,23 +121,22 @@ def main():
line = pv.lines_from_points(arch, close=False)
pl.add_mesh(line, color="red", line_width=2)
hide_cursor()
y, x = get_position()
kitty.hide_cursor()
y, x = kitty.get_position()
print("\n" * 25, end="")
frames = []
try:
if not args.external:
while True:
pl.camera.Azimuth(1)
buf: BytesIO = BytesIO()
pl.screenshot(buf, transparent_background=True, window_size=(512, 512))
set_position(y - 25, x)
draw_to_terminal(buf)
kitty.set_position(y - 25, x)
kitty.draw_to_terminal(buf)
else:
pl.show()
finally:
show_cursor()
kitty.show_cursor()
if __name__ == "__main__":