From 80fd76c485dc851547fa05d96fa7335ecb835f26 Mon Sep 17 00:00:00 2001 From: Alexander Hosking Date: Sun, 17 Oct 2021 20:20:26 -0400 Subject: [PATCH] Media copy research and development --- mediacopy/.gitignore | 1 + mediacopy/file_copy.py | 67 +++++++++++++++++++++++++++++++++++++++ mediacopy/new_scans.py | 19 +++++++++++ mediacopy/test_menu.py | 71 ++++++++++++++++++++++++++++++++++++++++++ mediacopy/tkinter.py | 37 ++++++++++++++++++++++ 5 files changed, 195 insertions(+) create mode 100644 mediacopy/.gitignore create mode 100644 mediacopy/file_copy.py create mode 100644 mediacopy/new_scans.py create mode 100644 mediacopy/test_menu.py create mode 100644 mediacopy/tkinter.py diff --git a/mediacopy/.gitignore b/mediacopy/.gitignore new file mode 100644 index 0000000..03bd412 --- /dev/null +++ b/mediacopy/.gitignore @@ -0,0 +1 @@ +*.env diff --git a/mediacopy/file_copy.py b/mediacopy/file_copy.py new file mode 100644 index 0000000..b383295 --- /dev/null +++ b/mediacopy/file_copy.py @@ -0,0 +1,67 @@ +import os, time, sys +from shutil import copy2 +import filecmp +import pathlib +from PIL import Image, ExifTags +import pendulum + +INGEST_DIR = pathlib.PureWindowsPath(r'\\192.168.1.4\photos\z_temp\external_backup\olympus\DCIM\100OLYMP') +PHOTO_LIBRARY = '//192.168.1.4/photos/photo_library/' +file_list = os.listdir(INGEST_DIR) +# print(file_list) +move_list = [] + +for item in file_list: + cur_file = pathlib.Path(os.path.join(INGEST_DIR, item)) + # print(cur_file) + # print("last modified: %s" % time.ctime(os.path.getmtime(cur_file))) + # created_date = cur_file.stat().st_ctime + + ##Check for Exif Data + ## if no exif data revert to file created time + try: + created_date = Image.open(cur_file)._getexif()[36867] + parsed_date = pendulum.parse(created_date) + except: + created_date = (time.ctime(os.path.getctime(cur_file))) + parsed_date = pendulum.parse(created_date, strict=False) + + filename, file_extension = os.path.splitext(item) + filename = item ## Critical to the process + if not file_extension.lower() == ".nef" and not file_extension.lower() == ".jpg": + continue + + # print(filename, file_extension) + # print(created_date) + # print() + + # print(parsed_date) + year = parsed_date.year + month = str(parsed_date.month).zfill(2) + day = str(parsed_date.day).zfill(2) + destination = "%s%s/%s/%s/%s" % (PHOTO_LIBRARY, year, month, day, filename) + # print(destination) + print("We want to move %s to %s%s/%s/%s." % (filename, PHOTO_LIBRARY, year, month, day)) + + ## check if the directory exists + if not os.path.isdir(os.path.join(PHOTO_LIBRARY, str(year))): + print("We couldn't find your directory") + os.makedirs(os.path.join(PHOTO_LIBRARY, year)) + if not os.path.isdir(os.path.join(PHOTO_LIBRARY, str(year), str(month))): + print("We couldn't find your directory") + os.makedirs(os.path.join(PHOTO_LIBRARY, str(year), str(month))) + if not os.path.isdir(os.path.join(PHOTO_LIBRARY, str(year), str(month), str(day))): + print("We couldn't find your directory") + os.makedirs(os.path.join(PHOTO_LIBRARY, str(year), str(month), str(day))) + + ## We should be copying, creating a source and destination hash + ## comparing the files and then deleting the source + print() + print("Copying %s to %s" % (cur_file, destination)) + copy2(cur_file, destination) + if filecmp.cmp(cur_file, destination) == True: + print("%s and %s are a match. Time to delete %s" % (cur_file, destination, cur_file)) + os.remove(cur_file) + +### TODO: +### Find files with no extension and save them + directory to a file \ No newline at end of file diff --git a/mediacopy/new_scans.py b/mediacopy/new_scans.py new file mode 100644 index 0000000..8b7c8b6 --- /dev/null +++ b/mediacopy/new_scans.py @@ -0,0 +1,19 @@ +''' +Honestly just check to see what the newest file is and if it is newer than the last one we saw +Send a push notification to Alex + +Aspirations: +[] Suggest new names +[] Rename them in the tool +''' +import os +import time + +SCANS_DIR = r'\\192.168.1.4\scans' +listing = os.listdir(SCANS_DIR) +print(listing) + +for item in listing: + cur_file = os.path.join(SCANS_DIR, item) + # print("last modified: %s" % time.ctime(os.path.getmtime(cur_file))) # Last Modified Time + print("%s Created: %s" % (item, time.ctime(os.path.getctime(cur_file)))) \ No newline at end of file diff --git a/mediacopy/test_menu.py b/mediacopy/test_menu.py new file mode 100644 index 0000000..a39d7b1 --- /dev/null +++ b/mediacopy/test_menu.py @@ -0,0 +1,71 @@ +from PyInquirer import style_from_dict, Token, prompt, Separator +from pprint import pprint + + +style = style_from_dict({ + Token.Separator: '#cc5454', + Token.QuestionMark: '#673ab7 bold', + Token.Selected: '#cc5454', # default + Token.Pointer: '#673ab7 bold', + Token.Instruction: '', # default + Token.Answer: '#f44336 bold', + Token.Question: '', +}) + + +questions = [ + { + 'type': 'checkbox', + 'message': 'Select toppings', + 'name': 'toppings', + 'choices': [ + Separator('= The Meats ='), + { + 'name': 'Ham' + }, + { + 'name': 'Ground Meat' + }, + { + 'name': 'Bacon' + }, + Separator('= The Cheeses ='), + { + 'name': 'Mozzarella', + 'checked': True + }, + { + 'name': 'Cheddar' + }, + { + 'name': 'Parmesan' + }, + Separator('= The usual ='), + { + 'name': 'Mushroom' + }, + { + 'name': 'Tomato' + }, + { + 'name': 'Pepperoni' + }, + Separator('= The extras ='), + { + 'name': 'Pineapple' + }, + { + 'name': 'Olives', + 'disabled': 'out of stock' + }, + { + 'name': 'Extra cheese' + } + ], + 'validate': lambda answer: 'You must choose at least one topping.' \ + if len(answer) == 0 else True + } +] + +answers = prompt(questions, style=style) +pprint(answers) \ No newline at end of file diff --git a/mediacopy/tkinter.py b/mediacopy/tkinter.py new file mode 100644 index 0000000..1391f72 --- /dev/null +++ b/mediacopy/tkinter.py @@ -0,0 +1,37 @@ +import tkinter as tk +from tkinter import filedialog +# from tkinter import * + +class Application(tk.Frame): + def __init__(self, master=None): + super().__init__(master) + self.master = master + self.pack() + self.create_widgets() + + def create_widgets(self): + self.copy_from = tk.Button(self) + self.copy_from["text"] = "Copy from..." + # self.copy_from["command"] = self.get_dir(self.copy_from) + self.copy_from.pack(side="top") + + self.copy_to = tk.Button(self) + self.copy_to["text"] = "Copy to..." + # self.copy_to.bind('', self.get_dir(self.copy_to)) + self.copy_to.pack(side="top") + + + self.quit = tk.Button(self, text="QUIT", fg="red", + command=self.master.destroy) + self.quit.pack(side="bottom") + + def get_dir(self, the_widget): + folder_selected = filedialog.askdirectory() + if len(folder_selected) > 6: + the_widget.config(text=folder_selected) + + +root = tk.Tk() +app = Application(master=root) +app.copy_from.configure(command=app.get_dir(app.copy_from)) +app.mainloop() \ No newline at end of file