"""
download_tle.py - Run this once per week to download TLE data
Schedule this with cron (Linux/Mac) or Task Scheduler (Windows)
"""
import requests
from datetime import datetime

def download_tle(catnr=25544, filename='iss_tle.txt'):
    """Download TLE data from Celestrak and save to file"""
    url = f'https://celestrak.org/NORAD/elements/gp.php?CATNR={catnr}&FORMAT=TLE'
    
    try:
        response = requests.get(url)
        response.raise_for_status()
        
        with open(filename, 'w') as f:
            f.write(response.text)
        
        print(f"TLE data downloaded successfully at {datetime.now()}")
        print(f"Saved to: {filename}")
        
    except Exception as e:
        print(f"Error downloading TLE: {e}")

if __name__ == '__main__':
    download_tle()