Esempio n. 1
0
 def __init__(self, config, service_type):
     self.__config = config
     self.info = {'details': []}
     if service_type == SERVICE_GOOGLE_DRIVE:
         self.service = GoogleDrive(config)
     elif service_type == SERVICE_ONEDRIVE:
         self.service = OneDrive(config)
     elif service_type == SERVICE_DROPBOX:
         raise NotImplementedError('not implemented yet!')
     elif service_type == SERVICE_SCP:
         self.service = ScpUpload(config)
Esempio n. 2
0
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
Esempio n. 3
0
import time
import schedule
import threading
from cache import Cache
from config import config
from onedrive import OneDrive
from utils import path_format

od = OneDrive()


class Process:
    tasks = []

    @staticmethod
    def runner():
        while True:
            schedule.run_pending()
            time.sleep(1)

    @staticmethod
    def refresh_token():
        od.get_access()
        od.get_resource()
        od.get_access(od.resource_id)

    @classmethod
    def refresh_difference(cls):
        cls.tasks.append({'full_path': config.start_directory})

    @classmethod
Esempio n. 4
0
__all__ = [
    'db', 'fjson', 'ip2loc', 'onedrive', 'redis', 'pat', 'sendgrid', 'sqlogger'
]

from flask_json import FlaskJSON
from flask_redis import FlaskRedis

from flask_sendgrid import SendGrid
from flask_sqlalchemy_ import SQLAlchemy
from ip2loc import IP2Loc
from onedrive import OneDrive
from pypat import Pat
from sqlalchemy_ import BaseModel
from sqlogger import SQLogger

db = SQLAlchemy(Model=BaseModel)
fjson = FlaskJSON()
ip2loc = IP2Loc()
onedrive = OneDrive()
pat = Pat()
redis = FlaskRedis()
sendgrid = SendGrid()
sqlogger = SQLogger()
Esempio n. 5
0
def main():
    client_id = "your-app-id"
    client_secret = "your-app-code"
    o = OneDrive(client_id, client_secret)
    o.auth()

    res = o.getDriveList()
    printResult("driver list", res)

    res = o.getDriveInfo()
    printResult("driver info", res)

    res = o.getRecentItems()
    printResult("recent items", res)

    res = o.getSharedItems()
    printResult("shared items", res)
    
    res = o.getItemInfoByAppPath("/")
    printResult("app root path info", res)

    res = o.getItemInfoByCommonPath("/")
    printResult("common root path info", res)

    res = o.getItemChildrenByAppPath("/")
    printResult("children of app root path", res)
    
    res = o.getItemChildrenByCommonPath("/")
    printResult("children of common root path", res)

    res = o.createCommonDir("TEST_DIR", "/")
    printResult("create dir in common root dir", res)

    res = o.deleteCommonItem("/TEST_DIR")
    printResult("delete dir in common root dir", res)

    res = o.createAppDir("TEST_APP_DIR", "/")
    printResult("create dir in app root dir", res)

    res = o.deleteAppItem("/TEST_APP_DIR")
    printResult("delete dir in app root dir", res)

    res = o.createCommonDir("TEST_DIR", "/")
    res = o.copyItem("/TEST_DIR", "/", "TEST_DIR_COPY")
    res = o.deleteCommonItem("/TEST_DIR")
    time.sleep(2)
    res = o.deleteCommonItem("/TEST_DIR_COPY")
    printResult("copy dir in common root", res)

    res = o.createAppDir("TEST_DIR", "/")
    res = o.copyItem("/TEST_DIR", "/", "TEST_DIR_COPY", True, True)
    time.sleep(2)
    res = o.deleteAppItem("/TEST_DIR")
    res = o.deleteAppItem("/TEST_DIR_COPY")
    printResult("copy dir in app root", res)

    res = o.createCommonDir("TEST_DIR", "/")
    res = o.moveItem("/TEST_DIR", "/", "TEST_DIR_COPY")
    res = o.deleteCommonItem("/TEST_DIR_COPY")
    printResult("move dir in common root", res)

    res = o.createAppDir("TEST_DIR", "/")
    res = o.moveItem("/TEST_DIR", "/", "TEST_DIR_COPY", True, True)
    res = o.deleteAppItem("/TEST_DIR_COPY")
    printResult("move dir in app root", res)

    file_path = os.path.abspath(__file__)
    file_name = os.path.split(file_path)[1]
    res = o.uploadCommonFile(file_path, "/")
    printResult("upload local file to common root", res)

    os.mkdir("_TEMP")
    res = o.downloadCommonFile("/" + file_name, "./_TEMP")
    o.deleteCommonItem("/" + file_name)
    printResult("download common file from common root", res)
    
    res = o.uploadCommonDir("_TEMP", "/")
    shutil.rmtree("_TEMP")
    printResult("upload dir to common root", res)

    res = o.downloadCommonDir("/_TEMP", ".")
    shutil.rmtree("_TEMP")
    o.deleteCommonItem("/_TEMP")
    printResult("download dir from common root", res)