Created
December 31, 2022 19:26
-
-
Save ppdms/1235b582c1f11c0e541059b694671180 to your computer and use it in GitHub Desktop.
sort lecture photos into folders according to concurrent lectures
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PIL import Image | |
from datetime import datetime, timedelta | |
from os import listdir | |
from shutil import move | |
import re | |
filenames = listdir("images/") | |
schedule = [ # weekday, start, name | |
[0, 9, "Discrete"], | |
[0, 15, "CS"], | |
[0, 17, "Econ"], | |
[1, 9, "Python"], | |
[1, 11, "Discrete"], | |
[1, 13, "Econ"], | |
[2, 9, "CS"], | |
[2, 11, "Analysis"], | |
[2, 15, "Analysis"], | |
[3, 11, "Analysis"], | |
[4, 9, "Python"], | |
[4, 11, "Discrete"], | |
[4, 13, "Analysis"] | |
] | |
for filename in filter(lambda x: re.compile(r'^.*\.(jpeg|jpg)$').match(x), filenames): | |
image = Image.open(f"images/{filename}") | |
date = datetime.strptime(image.getexif()[306], "%Y:%m:%d %H:%M:%S") | |
for subject in schedule: | |
if date.weekday() == subject[0] and datetime(date.year, date.month, date.day, subject[1]) <= date <= datetime(date.year, date.month, date.day, subject[1]) + timedelta(hours=2): | |
move(f"images/{filename}", f"{subject[2]}/{filename}") # make folders first manually |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment