Skip to content

Commit

Permalink
Apply suggestion from @varnav
Browse files Browse the repository at this point in the history
  • Loading branch information
TheLastGimbus committed Jan 6, 2021
1 parent dc305da commit 643a682
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
9 changes: 8 additions & 1 deletion google_photos_takeout_helper/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ def main():
import piexif as _piexif
from fractions import Fraction # piexif requires some values to be stored as rationals
import math
if _os.name == 'nt':
import win32_setctime as _windoza_setctime

parser = _argparse.ArgumentParser(
prog='Photos takeout helper',
Expand Down Expand Up @@ -343,12 +345,17 @@ def set_creation_date_from_str(file: Path, str_datetime):
# God wish that americans won't have something like MM-DD-YYYY
# The replace ': ' to ':0' fixes issues when it reads the string as 2006:11:09 10:54: 1.
# It replaces the extra whitespace with a 0 for proper parsing
str_datetime = str_datetime.replace('-', ':').replace('/', ':').replace('.', ':').replace('\\', ':').replace(': ', ':0')[:19]
str_datetime = str_datetime.replace('-', ':').replace('/', ':').replace('.', ':').replace('\\',
':').replace(': ',
':0')[
:19]
timestamp = _datetime.strptime(
str_datetime,
'%Y:%m:%d %H:%M:%S'
).timestamp()
_os.utime(file, (timestamp, timestamp))
if _os.name == 'nt':
_windoza_setctime.setctime()
except Exception as e:
print('Error setting creation date from string:')
print(e)
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
piexif==1.1.3
win32-setctime==1.0.3

0 comments on commit 643a682

Please sign in to comment.