This repository has been archived by the owner on Oct 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
virtualTimer.py
executable file
·130 lines (117 loc) · 4.51 KB
/
virtualTimer.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
#!/usr/bin/env /usr/local/bin/python3.9
import pytz
import json
from datetime import datetime, time, timezone, timedelta
import os
import sys
from localStoragePy import localStoragePy
from logger import silentlog
localStorage = localStoragePy('ekstremedia-timelapse-exposure', 'sqlite')
tz = pytz.timezone('Europe/Oslo')
js = os.path.join(sys.path[0], "scripts/solartimes.json")
# mytz = datetime.now()
def getCurrentExposure():
max_exposure = 5000000
exposureRatio = 30390
min_exposure = 2000
default_exposure = min_exposure
# mytz = datetime(2021,2,5,15,34)
mytz = datetime.now()
mytz = tz.localize(mytz)
# print(f"mytz: {mytz}")
day = mytz.strftime('%d') # 05
month = mytz.strftime('%m')
dateStr = day+"-"+month
hour = mytz.strftime('%H:%M') # 05
# print(f"Now: {mytz}")
# print(f"Hour {hour}")
with open(js) as json_file:
solardata = json.load(json_file)
day = solardata[dateStr]
if not day['data']:
polar = True
polarType = day['sun']
else:
polar = False
sunrise = day['sunrise']
sunset = day['sunset']
# print(f"Mytz: {mytz}")
if not polar:
sunriseHour = int(sunrise[0:2])
sunriseMinute = int(sunrise[3:5])
sunsetHour = int(sunset[0:2])
sunsetMinute = int(sunset[3:5])
else:
# print(f"Polar time, sun: {polarType}")
if (polarType == 'never_sets'):
sunriseHour = 9
sunriseMinute = 00
sunsetHour = 12
sunsetMinute = 00
max_exposure = 10000
min_exposure = 2000
if (polarType == 'never_rises'):
sunriseHour = 22
sunriseMinute = 00
sunsetHour = 23
sunsetMinute = 00
max_exposure = max_exposure
min_exposure = 2000
sunriseToday = mytz.replace(hour=sunriseHour,minute=sunriseMinute, second=0, microsecond=0)
sunsetToday = mytz.replace(hour=sunsetHour,minute=sunsetMinute, second=0, microsecond=0)
# print(f"Sunrise: {sunriseToday}")
# print(f"Sunset: {sunsetToday}")
# {'data': True, 'sunrise': '08:32', 'solar_noon': '12:12', 'sunset': '15:52'}
# 17:05
# 8:50
# old 150
timeToStartDay = sunriseToday - timedelta(minutes=180)
# timeToStartDay = sunriseToday - timedelta(hours=1)
#old = 120
endOfDay = sunsetToday + timedelta(minutes=135)
# print(f"Time to start day: {timeToStartDay}")
# old = 50
timeToEndDay = sunsetToday + timedelta(minutes=20)
currentExposure = 5000000
# print(currentExposure)
# print(getExposure)
if (mytz < timeToStartDay or mytz > endOfDay):
currentExposure = max_exposure
else:
getExposure = localStorage.getItem('currentExposure')
if (str(getExposure) == 'None'):
if (mytz < timeToStartDay or mytz > endOfDay):
# print(f"None set, defaulting to {max_exposure}")
localStorage.setItem('currentExposure', max_exposure)
currentExposure = max_exposure
elif(mytz>= timeToStartDay and mytz <= endOfDay):
# print(f"None set, defaulting to {default_exposure}")
localStorage.setItem('currentExposure', default_exposure)
currentExposure = default_exposure
# else:
if (str(getExposure) != 'None'):
currentExposure = int(getExposure)
# print(currentExposure)
if (mytz > timeToStartDay and mytz < timeToEndDay):
# print(currentExposure)
if (currentExposure > min_exposure):
currentExposure = currentExposure-exposureRatio
if (currentExposure < min_exposure):
currentExposure = min_exposure
else:
currentExposure = min_exposure
elif (mytz > timeToStartDay and mytz > timeToEndDay):
if (currentExposure < max_exposure):
currentExposure = currentExposure+exposureRatio
if (currentExposure > max_exposure):
currentExposure = max_exposure
localStorage.setItem('currentExposure', currentExposure)
silentlog(f"Exposure: {currentExposure}")
return int(currentExposure)
# mytz = datetime(2021,2,5,7,4)
# for i in range(140):
# mytz = mytz + timedelta(minutes=1)
# hr = mytz.strftime('%H:%M')
# ex = getCurrentExposure()
# ps = f"Time: {hr}, ex: {ex}"
# print(ps)