# Path: skyfield/eclipselib.py
# LUNAR_ECLIPSES = [
#     'Penumbral',
#     'Partial',
#     'Total',
# ]
# def lunar_eclipses(start_time, end_time, eph):
#     def f(t):
# 
# Path: skyfield/api.py
# N = E = +1.0
# S = W = -1.0


from collections import Counter
from skyfield import eclipselib
from skyfield.api import load, GREGORIAN_START
import datetime as dt

with load.open('https://eclipse.gsfc.nasa.gov/5MCLE/5MKLEcatalog.txt') as f:
    data = f.read()

ts = load.timescale()
ts.julian_calendar_cutoff = GREGORIAN_START

table = []
lines = data.decode('ascii').splitlines()

for line in lines[14:]:
    year = int(line[7:12])
    if year < 1 or year >= 3000:
    #if year < 1900 or year > 1920:
        continue
    datestr = line[8:29]
    d = dt.datetime.strptime(datestr, '%Y %b %d  %H:%M:%S')
    t = ts.tt(d.year, d.month, d.day, d.hour, d.minute, d.second)
    table.append((t, line[51]))

time0 = table[0][0]
timeN = table[-1][0]

start_time = ts.tt_jd(time0.whole - 1, time0.tt_fraction)
end_time = ts.tt_jd(timeN.whole + 1, timeN.tt_fraction)

start_time.whole -= 1.0
end_time.whole += 1.0

eph = load('de406.bsp')

# Path: skyfield/eclipselib.py
# LUNAR_ECLIPSES = [
#     'Penumbral',
#     'Partial',
#     'Total',
# ]
# def lunar_eclipses(start_time, end_time, eph):
#     def f(t):
# 
# Path: skyfield/api.py
# N = E = +1.0
# S = W = -1.0


# Path: design/eclipses_lunar.py
from collections import Counter
from skyfield import eclipselib
from skyfield.api import load, GREGORIAN_START
import datetime as dt


with load.open('https://eclipse.gsfc.nasa.gov/5MCLE/5MKLEcatalog.txt') as f:
    data = f.read()

ts = load.timescale()
ts.julian_calendar_cutoff = GREGORIAN_START

table = []
lines = data.decode('ascii').splitlines()

for line in lines[14:]:
    year = int(line[7:12])
    if year < 1 or year >= 3000:
    #if year < 1900 or year > 1920:
        continue
    datestr = line[8:29]
    d = dt.datetime.strptime(datestr, '%Y %b %d  %H:%M:%S')
    t = ts.tt(d.year, d.month, d.day, d.hour, d.minute, d.second)
    table.append((t, line[51]))

time0 = table[0][0]
timeN = table[-1][0]

start_time = ts.tt_jd(time0.whole - 1, time0.tt_fraction)
end_time = ts.tt_jd(timeN.whole + 1, timeN.tt_fraction)

start_time.whole -= 1.0
end_time.whole += 1.0

eph = load('de406.bsp')

t, y, details = eclipselib.lunar_eclipses(start_time, end_time, eph)