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
/
Timer.py
executable file
·122 lines (112 loc) · 4.27 KB
/
Timer.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
#!/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 *
localStorage = localStoragePy('ekstremedia-timelapse-exposure', 'sqlite')
tz = pytz.timezone('Europe/Oslo')
#mytz = datetime(2021,2,5,8,11);
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}")
exposure_max = 6000000
localStorage.setItem('exposure', exposure_max)
exposure_min = 4000
js = os.path.join(sys.path[0], "scripts/solartimes.json")
with open(js) as json_file:
solardata = json.load(json_file)
day = solardata[dateStr]
sunrise = day['sunrise']
sunset = day['sunset']
# print(f"Sunrise: {sunrise} - sunset: {sunset}")
sunriseHour = int(sunrise[0:2])
sunriseMinute = int(sunrise[3:5])
sunriseToday = mytz.replace(hour=sunriseHour,minute=sunriseMinute, second=0, microsecond=0)
sunsetHour = int(sunset[0:2])
sunsetMinute = int(sunset[3:5])
sunsetToday = mytz.replace(hour=sunsetHour,minute=sunsetMinute, second=0, microsecond=0)
startCountDown = sunriseToday - timedelta(hours=2)
startCountUp = sunsetToday
# + timedelta(hours=2)
#print("")
# print(f"startCountDown {startCountDown}")
# print(f"startCountUp {startCountUp}")
# print(f"Sunset {sunsetToday}")
#print(f"Start Countdown {startCountdown}")
# print(f"Start CountdownP {startCountdownP}")
#print(mytz > startCountdown)
# for i in range(120):
# startCountdown = startCountdown + timedelta(minutes=1)
# ex = int(localStorage.getItem('exposure'));
# print(f"{startCountdown}: {ex}")
# ex = ex - 50390
# localStorage.setItem('exposure', ex)
exposureRatio = 50390
def getCurrentExposure():
returnedValue = False
if (mytz > startCountDown and mytz < startCountUp):
checkCountDown = localStorage.getItem('countDown')
# print(f"checkCountDown: {checkCountDown}")
if (checkCountDown != 'on'):
checkCountDown = 'on'
max_exposure = 6000000
localStorage.setItem('countDown', checkCountDown)
localStorage.setItem('countUp', 'off')
currentExposure = max_exposure-exposureRatio
localStorage.setItem('currentExposure', currentExposure)
returnedValue = True
print("hx")
print(currentExposure)
else:
currentExposure = localStorage.getItem('currentExposure')
res = isinstance(currentExposure, str)
if (str(res)):
currentExposure = 1000;
if (int(currentExposure)<2000):
localStorage.setItem('currentExposure', 2000)
returnedValue = True
print("hy")
print(2000)
else:
localStorage.setItem('currentExposure', currentExposure)
returnedValue = True
print("hb")
print(currentExposure)
else:
# print("hf")
checkCountUp = localStorage.getItem('countUp')
# print(f"checkCountUp: {checkCountUp}")
if (checkCountUp != 'on'):
checkCountDown = 'off'
checkCountUp = 'on'
max_exposure = 6000000
localStorage.setItem('countDown', 'off')
localStorage.setItem('countUp', checkCountUp)
currentExposure = int(localStorage.getItem('currentExposure'))+exposureRatio
localStorage.setItem('currentExposure', currentExposure)
returnedValue = True
print(currentExposure)
else:
currentExposure = int(localStorage.getItem('currentExposure'))+exposureRatio
localStorage.setItem('currentExposure', currentExposure)
if (currentExposure>6000000):
returnedValue = True
print(6000000)
else:
returnedValue = True
print(currentExposure)
# print("h2")
if not returnedValue:
print("No return value")
# print("er")
print(int(localStorage.getItem('currentExposure')))
getCurrentExposure()