-
Notifications
You must be signed in to change notification settings - Fork 0
/
timely_time_v0.3.py
150 lines (110 loc) · 3.96 KB
/
timely_time_v0.3.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# %%
#!python -m venv .venv
#!pip install suntime
#!pip install geopy
#!pip install pipreqs
#!pip install pyinstaller
#some of the code here is adapted from https://www.geeksforgeeks.org/create-a-gui-to-get-sunset-and-sunrise-time-using-python/
# %% [markdown]
# # Imports
# %%
from datetime import datetime, date, timedelta
import time as sleepy # need to call it something else because 'time' collides with datetime stuff
import os
from suntime import Sun
from geopy.geocoders import Nominatim
from IPython.display import clear_output
# %%
print("""
______ ____ ___ ___ ___ _ __ __ ______ ____ ___ ___ ___
| || || | | / _]| | | | | | || || | | / _]
| | | | | _ _ | / [_ | | | | | | | | | | _ _ | / [_
|_| |_| | | | \_/ || _]| |___ | ~ | |_| |_| | | | \_/ || _]
| | | | | | || [_ | ||___, | | | | | | | || [_
| | | | | | || || || | | | | | | | || |
|__| |____||___|___||_____||_____||____/ |__| |____||___|___||_____|
A universal time format to draw ire.
By Jeff Industries and Fabrication
MIT License
v0.3 released 2022-10-03
""")
# %% [markdown]
# # Helpful vars and funcs
# some of these are probably unused
# %%
#most days have 86,400 seconds (I KNOW)
tradtional_hours_in_day = 24
traditional_minutes_daily = 1440
traditional_seconds_daily = 86400
new_hours_in_day = 100
new_minutes_in_day = 10000
new_seconds_in_day = 1000000
# %%
def convertUTCto180thMeridian(in_datetime):
return in_datetime - timedelta(hours= 12)
def timeAt180thMeridian():
'''Gets current time at 180th meridian in traditional datetime format'''
return datetime.utcnow() - timedelta(hours=12)
def convertToTimely(in_time):
"""Returns a decimal, always <= 1.0."""
conv_total_seconds = in_time.hour * 3600 + in_time.minute *60 + in_time.second
conv_time_decimal = conv_total_seconds / traditional_seconds_daily
return conv_time_decimal
def calc_sunrise():
return convertToTimely(
convertUTCto180thMeridian(
sun.get_sunrise_time()
)
)
def calc_sunset():
return convertToTimely(
convertUTCto180thMeridian(
sun.get_sunset_time()
)
)
# %% [markdown]
# # Sun
# %%
# Nominatim API to get latitude and longitude
# User agent is name of app, probably so they can block if it gets too many requests.
geolocator = Nominatim(user_agent="timely_time")
# %%
location = None
while location is None: #this is a stupid way to do this, but geolocator will return a blank string if city not found
place = str(input("Enter city name: ").lower())
location = geolocator.geocode(place)
# latitude and longitude fetch
latitude = location.latitude
longitude = location.longitude
#sun object we'll pass to the sunrise/set calculators
sun = Sun(latitude, longitude)
if location is None:
print("No cities found named: ", place, "It's either too small or misspelled.\n------\n\n")
print("Success!\n\t", location, latitude, longitude)
# %% [markdown]
# # Time Output
# could definitely be optimized by not constantly re-calcing the sunrise/sunset
# %%
while True:
# Clear the output in jupyter
clear_output(wait=True)
# Clear the output on standard out
os.system('cls')
timely_time = convertToTimely(timeAt180thMeridian())
sunrise = calc_sunrise()
sunset = calc_sunset()
#doing fancy stuff with f-strings here to make sure that the float's always represented as 4 digits
print(f"""
{location.address}
Global Time = {timely_time*100:.2f}
☼▲ = {sunrise*100:.2f} || ☼▼ = {sunset*100:.2f}
"""
)
sleepy.sleep(4)
# %% [markdown]
# # Installation nonsense
# Things in here will generally be commented out, except when making new version.
# %%
#!pipreqs --encoding=utf8 --force
# %%
#!pyinstaller "base_100_time_v0.3.py" -y