-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathlunar_eclipse.py
executable file
·59 lines (53 loc) · 1.88 KB
/
lunar_eclipse.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env python3
#
# lunar_eclipse.py - by Don Cross - 2020-05-16
#
# Example Python program for Astronomy Engine:
# https://github.com/cosinekitty/astronomy
#
# Searches for the next 10 partial/total lunar eclipses after
# the current date, or a date specified on the command line.
#
# To execute, run the command:
# python3 lunar_eclipse.py [date]
#
import sys
from astronomy import Time, SearchLunarEclipse, NextLunarEclipse, EclipseKind, LunarEclipseInfo
from typing import List
def PrintEclipse(e: LunarEclipseInfo) -> None:
# Calculate beginning/ending of different phases
# of an eclipse by subtracting/adding the peak time
# with the number of minutes indicated by the "semi-duration"
# fields sd_partial and sd_total.
MINUTES_PER_DAY = 24 * 60
p1 = e.peak.AddDays(-e.sd_partial / MINUTES_PER_DAY)
print('{} Partial eclipse begins.'.format(p1))
if e.sd_total > 0.0:
t1 = e.peak.AddDays(-e.sd_total / MINUTES_PER_DAY)
print('{} Total eclipse begins.'.format(t1))
print('{} Peak of {} eclipse.'.format(e.peak, e.kind.name.lower()))
if e.sd_total > 0.0:
t2 = e.peak.AddDays(+e.sd_total / MINUTES_PER_DAY)
print('{} Total eclipse ends.'.format(t2))
p2 = e.peak.AddDays(+e.sd_partial / MINUTES_PER_DAY)
print('{} Partial eclipse ends.'.format(p2))
print()
def main(args: List[str]) -> int:
if len(args) == 1:
time = Time.Now()
elif len(args) == 2:
time = Time.Parse(args[1])
else:
print('USAGE: {} [yyyy-mm-ddThh:mm:ssZ]'.format(args[0]))
return 1
count = 0
e = SearchLunarEclipse(time)
while True:
if e.kind != EclipseKind.Penumbral:
PrintEclipse(e)
count += 1
if count == 10:
return 0
e = NextLunarEclipse(e.peak)
if __name__ == '__main__':
sys.exit(main(sys.argv))