Hello, it is delicious. This article is the second implementation commentary article of Because I don't want to deal with people with dirty desktops. It becomes. This time it may be a little short. If you want to know about the implementation, please see the article!
I used regular expressions and shutil here.
The genius of mac screenshots is that the file name has a capture time! Thanks to this, I no longer have to install something like exiftool. The prefix contains the prefix that is added to the head when screenshot. For more information here!
path="Screenshot 2020-10-22 10.28.04.png "
cvtpath = re.compile(
prefix + r"[\s\S]*?(\d{4}).(\d\d).(\d\d)[\s\D]*?(\d\d?).(\d\d).(\d\d)")
flag = re.search(cvtpath, path)
if flag is not None and len(flag.groups()) == 6:
date = flag.groups()
date = list(map(lambda x: int(x), date))
If you think about it, how do you know that you are at a certain time on a certain day of the week?
Solution: You can get the day of the week with datetime. All you have to do is make something like UNIX time!
day = dtdt(*date).strftime("%a") #You can get the day of the week
# print(day)
# > Thu
dateemb = date[3] * 60 + date[4] #Now that we have one value, we can compare it.
# print(dateemb)
# 628
Solution: If you don't have an os, just rely on shutil!
import shutil
shutil.move(oldpath, newdir)
Thank you for reading. The previous article is here
Recommended Posts