-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdraft.py
103 lines (83 loc) · 3.09 KB
/
draft.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import exifread
import glob
import os
import time
import cv2
def get_photo_date(file_name):
# Open image file for reading (binary mode)
file = open(file_name, 'rb')
# Return Exif tags
tags = exifread.process_file(file, stop_tag="EXIF DateTimeOriginal")
# print("Number: ", "\t", tags) # For testing
time_n_date = tags["EXIF DateTimeOriginal"]
new_time_n_date = str(time_n_date)
date = new_time_n_date.split(" ")[0]
new_date = date.split(":")
# year = new_date[0] # For remembering of order
# month = new_date[1]
# day = new_date[2]
return new_date
def get_year(new_list):
res = new_list[0]
return res
def get_month(new_list):
res = new_list[1]
return res
def get_day(new_list):
res = new_list[2]
return res
def create_dirs(fisrPart, year_loc, month_loc):
# n_path = str("C:/Sorted/" + year_loc + "/" + month_loc)
n_path = str(fisrPart+"/" + year_loc + "/" + month_loc)
try:
os.makedirs(n_path, exist_ok = True)
print("Directory '%s' created successfully" % n_path)
except OSError as error:
print("Directory '%s' can not be created")
def process_all(file, destination_folder):
file_name = file.split("\\")[1]
photo = get_photo_date(file)
day = get_day(photo) # Currently not used
month = get_month(photo)
year = get_year(photo)
image = cv2.imread(file)
# create_dirs("C:/Sorted/", str(year), str(month))
# name = str('C:/Sorted/' + year + '/' + month + '/' + file_name)
create_dirs(destination_folder, str(year), str(month))
name = str(destination_folder + '/' + year + '/' + month + '/' + file_name)
cv2.imwrite(name, image)
# print(name)
def creation_date_video(path_to_file):
"""
Currently not implemented
First print returns date of modifications to the video file
Second print prints date of Creation of the video file, literally time when it was written to folder
"""
print("Last modified: %s" % time.ctime(os.path.getmtime(path_to_file)))
print("Created: %s" % time.ctime(os.path.getctime(path_to_file)))
# return os.path.getctime(path_to_file)
def main_one(string_path_to_folder, destination_folder):
"""We give location of folder as input"""
# .jpg and .JPG are the same
# photos = glob.glob("C:/Personal/pp2_photo/dataBase/*.JPG") # Examples of location format
# pho = glob.glob("C:/Personal/pp2_photo/dataBase/*.jpg")
photos = glob.glob(string_path_to_folder+"/*.JPG")
print("Number of files: ", len(photos))
for k in photos:
print(get_photo_date(k))
process_all(k, destination_folder)
# path = os.getcwd()
# print("The current working directory is %s" % path)
# main_one("C:/Personal/pp2_photo/dataBase")
"""TESTING PART"""
# for i in photos:
# process_all(i)
'''
FOR TESTING PURPOSES
file = open(i, 'rb')
Return Exif tags
tags = exifread.process_file(file, stop_tag="EXIF DateTimeOriginal")
dateTaken = tags["EXIF DateTimeOriginal"]
print(dateTaken)
'''
# creation_date_video("C:/Personal/pp2_photo/video/school_collage_4.mp4")