-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCamoPy.py
More file actions
57 lines (49 loc) · 1.75 KB
/
CamoPy.py
File metadata and controls
57 lines (49 loc) · 1.75 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
52
53
54
55
56
57
import logging
import time
import json
from time import sleep
from camera import Camera
from onedrive import OneDrive
from mail import Mail
from taskWeb import TaskWeb
def main(args):
logging.basicConfig(format='%(asctime)-15s - %(levelname)s:%(message)s', filename='camopy.log', level=logging.DEBUG)
with open('./config.json', 'r') as fichier:
config = json.load(fichier)
mythread = TaskWeb(config)
mythread.start()
mail = Mail(config)
path = config["images"]["path"]
onedrive = OneDrive(config)
itemImages = onedrive.getItem("root", "Images")
itemCamopy = onedrive.getItem(itemImages.id, config["oneDrive"]["directory"])
if itemCamopy == None:
itemCamopy = onedrive.createFolder(itemImages.id, config["oneDrive"]["directory"])
sendMail = True
camera = Camera(config)
run = True
while run :
start = time.clock()
fileName = camera.capture(path)
end = time.clock()
#logging.debug("Motion detection : {}".format(end - start))
if (fileName != ""):
start = time.clock()
onedrive.upload(itemCamopy.id, path, fileName)
end = time.clock()
logging.info("Uploaded file {} : {}".format(fileName, end - start))
if sendMail:
#message = "\n".join(config["mail"]["message"])
#mail.connect()
#mail.sendMessage(message)
#mail.disConnect()
sendMail = False
lastMail = time.clock()
logging.info("email sent")
else:
if time.clock() - lastMail > config["mail"]["wait"] :
sendMail = True
return 0
if __name__ == '__main__':
import sys
sys.exit(main(sys.argv))