first commit
This commit is contained in:
41
grab.py
Normal file
41
grab.py
Normal file
@@ -0,0 +1,41 @@
|
||||
# -*- coding:utf-8 -*-
|
||||
|
||||
"""
|
||||
Grab photos from camera and store them.
|
||||
"""
|
||||
import os
|
||||
import shutil
|
||||
import itertools
|
||||
from .config import CAMERA_PATH, BACKUP_PATH, IMPORT_PATH
|
||||
|
||||
|
||||
def _copy_files(files, target_dir):
|
||||
print("copy {files} to {target_dir}")
|
||||
# for f in files:
|
||||
# shutil.copy(f, target_dir)
|
||||
|
||||
|
||||
def _get_filenames(folder):
|
||||
# TODO: exact location of files is lost, but will be used !
|
||||
# Could return a dict{ filename: full_path }
|
||||
return set(
|
||||
itertools.chain.from_iterable(
|
||||
filenames for _, _, filenames in os.walk(folder)
|
||||
))
|
||||
|
||||
|
||||
def backup(files):
|
||||
_copy_files(files, BACKUP_PATH)
|
||||
|
||||
|
||||
def prepare_import(files):
|
||||
_copy_files(files, IMPORT_PATH)
|
||||
|
||||
|
||||
def grab():
|
||||
# Get new files from camera
|
||||
camera_files = _get_filenames(CAMERA_PATH)
|
||||
backup_files = _get_filenames(BACKUP_PATH)
|
||||
new_files = camera_files.difference(backup_files)
|
||||
backup(new_files)
|
||||
prepare_import(new_files)
|
||||
Reference in New Issue
Block a user