-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsetup.py
60 lines (41 loc) · 1.5 KB
/
setup.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
import os
from crontab import CronTab
import yaml
import pickle
from opensensemapAPI import createSensebox
# Read config.yaml file
with open("config.yaml", 'r') as stream:
yamlData = yaml.safe_load(stream)
path = yamlData["folderPath"]
environmentPath = yamlData["environmentPath"]
update = yamlData["sensebox"]["updateeveryhour"]
# Read config.yaml file
with open("config.yaml", 'r') as stream:
yamlData = yaml.safe_load(stream)
email = yamlData["sensebox"]["account"]["email"]
password = yamlData["sensebox"]["account"]["password"]
senseboxName = yamlData["sensebox"]["senseboxName"]
lat = yamlData["sensebox"]["coordinates"]["latitude"]
lng = yamlData["sensebox"]["coordinates"]["longitude"]
senseboxId = yamlData["sensebox"]["id"]
path = yamlData["folderPath"]
print(senseboxId)
# post a sensebox if the one mentioned in the config.yaml is not already there
if senseboxId == "notSet":
createSensebox(email, password, lat, lng)
with open('species.pkl', 'wb') as f:
pickle.dump({"all" : 0}, f, pickle.HIGHEST_PROTOCOL)
with open('speciesHistory.pkl', 'wb') as f:
pickle.dump({}, f, pickle.HIGHEST_PROTOCOL)
os.makedirs("imagesLastHour", exist_ok=True)
os.makedirs("processed", exist_ok=True)
cron = CronTab(user = True)
job= cron.new(command = "cd " + path + " && " + environmentPath + "/bin/python "+ " reset.py")
if update < 1 :
minutes = 60 * update
print(minutes)
job.every(minutes).minutes()
else:
hour = int(update)
job.every(hour).hours()
cron.write()