-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsun_moon_cli.py
77 lines (71 loc) · 2.07 KB
/
sun_moon_cli.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/python3
# -*- coding:utf-8 -*-
# Source code: https://github.com/cloudedbats/sun_moon_calculator
# Author: Arnold Andreasson, 2025.
# License: MIT, see http://opensource.org/licenses/mit.
import click
import datetime
import utils
current_year = datetime.date.today().year
@click.command()
@click.option(
"--latitude",
type=float,
default=57.89,
prompt="Latitude",
help="Latitude as decimal degree, for example 57.89",
)
@click.option(
"--longitude",
type=float,
default=12.34,
prompt="Longitude",
help="Longitude as decimal degree, for example 12.34",
)
@click.option(
"--year",
type=int,
default=current_year,
prompt="Year",
help="Year",
)
@click.option(
"--name",
type=str,
default="",
prompt="Name (optional)",
help="The name of the place. This field is optional.",
)
def calculate_sun_moon(latitude, longitude, year, name):
""" """
# Calculate.
sun_moon_to_excel = utils.SunMoonToExcel()
sun_moon_to_excel.generate_data(
latitude_dd=latitude,
longitude_dd=longitude,
start_year=year,
end_year=year,
)
# Save to file.
filename = "sun_moon_" + str(year) + ".xlsx"
if len(name) > 0:
filename = "sun_moon_" + name + "_" + str(year) + ".xlsx"
sun_moon_to_excel.create_report(filename)
if __name__ == "__main__":
""" """
print("\n\nSun moon calculator")
print("-------------------")
print("This tool will create an Excel file with daily information ")
print("about sunset, dusk, dawn, sunrise, and similar for the moon.")
print("")
print("Source code: https://github.com/cloudedbats/sun_moon_calculator")
print("")
print("Input used by the Sun moon calculator is position and year.")
print("Position should be given as latitude and longitude, both in")
print("the decimal degree format with decimal point, see default values.")
print("A name for the position can be set, but is not mandatory.")
print("Press Ctrl-C to terminate.\n")
try:
calculate_sun_moon()
except:
pass