def process():
    logger = logging.getLogger(__name__)
    files = sorted(
        [file for file in os.listdir(unprocessed_dir) if not file[0] == '.'])
    if len(files) > 0:
        logger.warning("Processing files in the order: {}".format(files))
    for file in files:
        path = os.path.join(unprocessed_dir, file)
        # QR code if present
        try:
            qr_codes = [
                qr_object.data.decode()
                for qr_object in decode(Image.open(path))
            ]
            for qr_code in qr_codes:
                update_reference(qr_code)
        except Exception as e:
            logger.error(e)
        # Process
        try:
            for match in last_reference['matches']:
                upload_to_box(path, match['box_folder_id'],
                              match['section_name'])
            # upload_to_s3(path)
            done_path = desktop_uploader.make_parallel_path(
                unprocessed_dir, done_dir, path)
            desktop_uploader.move(path, done_path)
        except Exception as e:
            logger.error(e)
            error_path = desktop_uploader.make_parallel_path(
                unprocessed_dir, error_dir, path)
            desktop_uploader.move(path, error_path)
 def test_make_parallel_path_4(self):
     src_dir = "/Users/russelltran/Desktop/magic_uploader/unprocessed"
     dst_dir = "/Users/russelltran/Desktop/magic_uploader/done"
     src_path = "/Users/russelltran/Desktop/magic_uploader/unprocessed/trout/computer/watermelon.jpg"
     self.assertEqual(
         main.make_parallel_path(src_dir, dst_dir, src_path),
         "/Users/russelltran/Desktop/magic_uploader/done/{}/trout/computer/watermelon.jpg"
         .format(datetime.today().strftime('%Y-%m-%d')))
 def test_make_parallel_path_2(self):
     src_dir = "/Users/russelltran/Desktop/magic_uploader/unprocessed"
     dst_dir = "/Users/russelltran/Desktop/magic_uploader/done"
     src_path = "/Users/russelltran/Desktop/magic_uploader/unprocessed/watermelon.jpg"
     self.assertEqual(
         main.make_parallel_path(src_dir,
                                 dst_dir,
                                 src_path,
                                 add_date_subdir=False),
         "/Users/russelltran/Desktop/magic_uploader/done/watermelon.jpg")
 def test_make_parallel_path(self):
     src_dir = "/apples/bananas"
     dst_dir = "/chair/table"
     src_path = "/apples/bananas/everything.jpg"
     self.assertEqual(
         main.make_parallel_path(src_dir,
                                 dst_dir,
                                 src_path,
                                 add_date_subdir=False),
         "/chair/table/everything.jpg")