Skip to content

Instantly share code, notes, and snippets.

@cbassa
Created July 24, 2021 19:56
Show Gist options
  • Save cbassa/09ff869e3852238bcef538366469beef to your computer and use it in GitHub Desktop.
Save cbassa/09ff869e3852238bcef538366469beef to your computer and use it in GitHub Desktop.
Simple TLE parsing script
#!/usr/bin/env python3
from sgp4.api import Satrec
from sgp4.earth_gravity import wgs84
if __name__ == "__main__":
with open("iss.txt", "r") as fp:
lines = fp.readlines()
sats = []
for i in range(len(lines) - 1):
if (lines[i][0] == "1") and (lines[i+1][0] == "2"):
sats.append(Satrec.twoline2rv(lines[i], lines[i+1]))
for sat in sats:
print(f"NORAD: {sat.satnum}")
print(f"Epoch: {sat.epochyr}{sat.epochdays:013.10f}")
print(f"Perigee: {sat.altp * wgs84.radiusearthkm:.2f} km")
print(f"Apogee: {sat.alta * wgs84.radiusearthkm:.2f} km")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment