forked from johncaijing/AndroidTips
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimeUpdaterP.py
More file actions
47 lines (32 loc) · 818 Bytes
/
TimeUpdaterP.py
File metadata and controls
47 lines (32 loc) · 818 Bytes
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
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import datetime
import re
class TimeUpdater(object):
"""docstring for TimeUpdaterP"""
def __init__(self, filePath):
self.filePath = filePath
def read(self):
f = open(self.filePath,'r')
readStr = f.read()
f.close()
return readStr
def getCurrentDateStr(self):
return datetime.datetime.now().strftime("%Y-%m-%d %H:%M")
def write(self,str):
f = open(self.filePath,'w')
f.write(str)
f.close()
def update(self):
dateStr = self.getCurrentDateStr()
pattern=r'[0-9]{4}[-][0-9]{2}[-][0-9]{2}\s[0-9]{2}[:][0-9]{2}'
str = self.read()
updateStr = re.sub(pattern,dateStr,str)
self.write(updateStr)
def main():
updater = TimeUpdater('./README.md')
updater.update()
if __name__=='__main__':
print('start')
main()
print('finish')