-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathriseset.py
executable file
·39 lines (35 loc) · 1.32 KB
/
riseset.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
#!/usr/bin/env python3
#
# riseset.py - by Don Cross - 2019-07-28
#
# Example Python program for Astronomy Engine:
# https://github.com/cosinekitty/astronomy
#
# This program calculates sunrise, sunset, moonrise, and moonset
# times for an observer at a given latitude and longitude.
#
# To execute, run the command:
# python3 riseset.py latitude longitude [yyyy-mm-ddThh:mm:ssZ]
#
import sys
from astronomy import Body, Time, Direction, SearchRiseSet
from astro_demo_common import ParseArgs
from typing import List, Optional
def PrintEvent(name: str, time: Optional[Time]) -> None:
if time is None:
raise Exception('Failure to calculate ' + name)
print('{:<8s} : {}'.format(name, time))
def main(args: List[str]) -> int:
observer, time = ParseArgs(args)
sunrise = SearchRiseSet(Body.Sun, observer, Direction.Rise, time, 300)
sunset = SearchRiseSet(Body.Sun, observer, Direction.Set, time, 300)
moonrise = SearchRiseSet(Body.Moon, observer, Direction.Rise, time, 300)
moonset = SearchRiseSet(Body.Moon, observer, Direction.Set, time, 300)
PrintEvent('search', time)
PrintEvent('sunrise', sunrise)
PrintEvent('sunset', sunset)
PrintEvent('moonrise', moonrise)
PrintEvent('moonset', moonset)
return 0
if __name__ == '__main__':
sys.exit(main(sys.argv))