import requests
from pathlib import Path
from datetime import date, timedelta

def download_file(date: str):
    filename = f"/home/acein/public_html/railways.acetians.in/api/downloads/data_{date}.json"

    # Replace this with your actual public URL pattern
    url = f"https://railmadad.indianrailways.gov.in/financial_year_reports/drill_api_response_{date}.json"

    output_path = Path(filename)

    response = requests.get(url, timeout=60)
    response.raise_for_status() 

    output_path.write_bytes(response.content)

    print(f"Downloaded: {filename}")
    print(f"Saved to: {output_path.absolute()}")


if __name__ == "__main__":
    today = date.today()
    date= today- timedelta(days=1)
    download_file(date)
     
     