コード例 #1
0
ファイル: capture.py プロジェクト: tinawen/dashboard
def vacuum():
    files = [f for f in os.listdir(WEBCAM_PICTURE_FOLDER) if os.path.isfile(os.path.join(WEBCAM_PICTURE_FOLDER, f))]
    for f in files:
        time_stamp = re.search('webcam(.+?).png', f).group(1)
        t = datetime.datetime.strptime(time_stamp, "%Y_%m_%d_%H_%M_%S")
        yesterday = datetime.datetime.now() - datetime.timedelta(days=1)
        # check if picture is too old
        if t < yesterday:
            try:
                os.remove('%s%s'% (WEBCAM_PICTURE_FOLDER, f))
                print "removing ", '%s%s'% (WEBCAM_PICTURE_FOLDER, f)
                # remove from dropbox
                client = authenticate_to_dropbox()
                response = client.file_delete(f)
                print "deleted from dropbox: ", response
            except:
                print "can't remove file %s", f
コード例 #2
0
def vacuum():
    files = [
        f for f in os.listdir(WEBCAM_PICTURE_FOLDER)
        if os.path.isfile(os.path.join(WEBCAM_PICTURE_FOLDER, f))
    ]
    for f in files:
        time_stamp = re.search('webcam(.+?).png', f).group(1)
        t = datetime.datetime.strptime(time_stamp, "%Y_%m_%d_%H_%M_%S")
        yesterday = datetime.datetime.now() - datetime.timedelta(days=1)
        # check if picture is too old
        if t < yesterday:
            try:
                os.remove('%s%s' % (WEBCAM_PICTURE_FOLDER, f))
                print "removing ", '%s%s' % (WEBCAM_PICTURE_FOLDER, f)
                # remove from dropbox
                client = authenticate_to_dropbox()
                response = client.file_delete(f)
                print "deleted from dropbox: ", response
            except:
                print "can't remove file %s", f
def lreplace(pattern, sub, string):
    return re.sub('^%s' % pattern, sub, string)

# make connection to dropbox
print "Connecting to dropbox..."
sess = session.DropboxSession(args.app_key, args.app_secret, args.access_type)
sess.set_token(args.access_token_key, args.access_token_secret)
client = client.DropboxClient(sess)

# get list of files for args.dropbox_dir
print "Fetching list of files in:", args.dropbox_dir
metadata = client.metadata(args.dropbox_dir)
def files_only(metadata): return metadata['is_dir'] == False
files = map(lambda metadata: metadata['path'], filter(files_only, metadata['contents']))

# download files to args.dest_dir
assure_path_exists(args.dest_dir)
for file in files:
    dest_file = args.dest_dir + lreplace(args.dropbox_dir, '', file)
    print "Downloading file: %s to: %s" % (file, dest_file)
    response = client.get_file(file)
    with open(dest_file, 'wb') as out:
        while not response.isclosed():
            out.write(response.read(1024 * 1024))
    
# remove files in args.dropbox_dir
if args.remove_downloaded_files == True:
    for file in files:
        print "Removing file: %s from dropbox" % (file)
        client.file_delete(file)
コード例 #4
0
ファイル: dropbox_down.py プロジェクト: sidmutha/CloudXCloud
def delete_file(src):
    client.file_delete(src)
コード例 #5
0
def delete_file(filename):
	"""
	Deletes a file on Dropbox
	"""
	print client.file_delete(filename)
コード例 #6
0
ファイル: dropbox_down.py プロジェクト: sidmutha/CloudXCloud
def delete_file(src):
	client.file_delete(src)
コード例 #7
0
ファイル: dbox_test.py プロジェクト: VIP000/Dropbox-2
#Get the same from your dropbox

if DEST_DIR in client.metadata('/')['contents'][0]['path']:
    SYNC_DIR_META = client.metadata(DEST_DIR)
    print 'Destination directory already exists'
else:
    client.file_create_folder(DEST_DIR)
    SYNC_DIR_META = client.metadata(DEST_DIR)
    print 'Just created the destination directory'
    
SYNC_DIR_META_LIST = {}
#Create a dictionary with the same info as SYNC_DIR_LIST
for file in SYNC_DIR_META['contents']:
    SYNC_DIR_META_LIST[os.path.split(file['path'])[1]] = file['bytes']

#Copy only if file does not exist on Dropbox, or size different from source(modified file) or does not start with . (hidden files)
for file in SYNC_DIR_LIST:
    if (file[0] != '.'):
        if (file not in SYNC_DIR_META_LIST):
            client.put_file(DEST_DIR + '/' + file,open(SYNC_DIR + '/' + file))
            print 'Copying ' + file + ' to Dropbox'
        if  (file in SYNC_DIR_META_LIST) and (SYNC_DIR_META_LIST[file] != SYNC_DIR_LIST[file]):
            client.file_delete(DEST_DIR + '/' + file)
            client.put_file(DEST_DIR + '/' + file,open(SYNC_DIR + '/' + file))
            print 'Updating ' + file + ' to Dropbox'
        
print 'Finished copying'