import argparse
import requests

DATASOURCE = "https://delacruz.belliniseven.ai/20260327.html"

def fetch_text():
    r = requests.get(DATASOURCE, timeout=10)
    r.raise_for_status()
    return r.text.splitlines()

def print_lines(lines, start_line, count):
    total = len(lines)
    end_line = start_line + count - 1

    if start_line < 1 or start_line > total:
        print(f"[ERROR] Start line {start_line} is out of range (1–{total})")
        return

    if end_line > total:
        end_line = total

    print(f"\n----- Lines {start_line} through {end_line} -----\n")

    for i in range(start_line - 1, end_line):
        print(lines[i])

    print("\n----- End -----\n")

def main():
    parser = argparse.ArgumentParser(description="Jump to a line range in remote HTML file.")
    parser.add_argument("-line", type=int, required=True, help="Starting line number")
    parser.add_argument("-for", dest="count", type=int, required=True, help="Number of lines to print")

    args = parser.parse_args()

    try:
        lines = fetch_text()
        print_lines(lines, args.line, args.count)
    except Exception as e:
        print(f"[ERROR] {e}")

if __name__ == "__main__":
    main()
