-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathset-update-date-FROM-note.py
74 lines (53 loc) · 2.44 KB
/
set-update-date-FROM-note.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
# coding=utf-8
from helper_routines import creation_date
from helper_routines import modification_date
from helper_routines import access_date
from helper_routines import checkPath
from helper_routines import getNotesFileNames
from helper_routines import stripEmptyTailLines
from helper_routines import quotePathForShell
import sys
import os
import codecs
from datetime import datetime
import math
import dateutil.parser
import time
from subprocess import call
import argparse
parser = argparse.ArgumentParser(description="My parser")
parser.add_argument('path')
args = parser.parse_args()
notesPath = os.path.join(args.path, '') # add trailing slash if it's not there
checkPath(notesPath)
notesFileNames = getNotesFileNames(notesPath)
for noteFileName in notesFileNames:
noteFilePath = notesPath + noteFileName
try:
#print(noteFilePath)
with codecs.open(noteFilePath, 'r', encoding='utf-8') as file:
lines = file.read().splitlines()
file.close()
stripEmptyTailLines(lines)
createdUpdated_line = lines[-1]
if createdUpdated_line.find("created:") == -1:
print "ERROR: there should be created: in " + noteFileName + " found instead: >" + createdUpdated_line + "<"
print noteFileName + " > " + createdUpdated_line
else:
theSplit = createdUpdated_line.split(" ")
#print(theSplit)
modificationDateParsed = dateutil.parser.parse(theSplit[4]+" " + theSplit[5])
#creationDateParsed = dateutil.parser.parse(theSplit[1]+" " + theSplit[2])
#print(modificationDateParsed)
theModificationDate = time.mktime(modificationDateParsed.timetuple())
#print(theTime)
#print(str(datetime.utcfromtimestamp(theTime)))
theAccessDate = math.floor(access_date(noteFilePath))
os.utime(noteFilePath,(theAccessDate, theModificationDate))
theSplitCreationDate = theSplit[1].split("-")
#command = 'SetFile -d ' + '"05/06/2019 "' + '00:00:00 ' + complete_path
command = 'SetFile -d ' + '"' + theSplitCreationDate[1] + "/" + theSplitCreationDate[2] + "/" + theSplitCreationDate[0] + " " + theSplit[2] + '" ' + quotePathForShell(noteFilePath)
print(command)
call(command, shell=True)
except Exception, e:
print("ERROR: " + str(e) )