-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
51 lines (38 loc) · 1.64 KB
/
main.py
File metadata and controls
51 lines (38 loc) · 1.64 KB
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
import pickle
import midtide.cal as cal
from midtide.core import *
def main():
# set forecast parameters
forecast_spot = "5842041f4e65fad6a7708841" # pb baby
forecast_days = 3
forecast_interval = 1
hit_api = False
create_cal_events = False
if hit_api:
forecast = surf_check(forecast_spot, forecast_days, forecast_interval)
with open('data/forecast.pkl', 'wb') as handle:
pickle.dump(forecast, handle, protocol=pickle.HIGHEST_PROTOCOL)
else:
with open('data/forecast.pkl', 'rb') as handle:
forecast = pickle.load(handle)
# print(forecast.get_dataframe("wave"))
# set mid tide optimization parameters
opt_start_time_rel = datetime.datetime(2022, 3, 6, 0, 15, 0) # how long after sunrise
opt_start_time_abs = datetime.datetime(2022, 3, 6, 7, 0, 0) # or no later than
opt_end_time_rel = datetime.datetime(2022, 3, 6, 0, 45, 0) # how long before sunset
opt_end_time_abs = datetime.datetime(2022, 3, 6, 19, 00, 0) # or no later than
params = OptimizationParams(opt_start_time_rel, opt_start_time_abs,
opt_end_time_rel, opt_end_time_abs)
sessions = get_surf_sessions(forecast, params)
# set credentials to access calendar
creds = cal.set_credentials()
# create calendar events
for session in sessions:
surf_event_json = cal.create_event_json(session)
# create calendar events or print to screen if debugging / testing
if create_cal_events:
cal.create_event(surf_event_json, creds)
else:
print(surf_event_json)
if __name__ == '__main__':
main()