-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
executable file
·36 lines (29 loc) · 951 Bytes
/
run.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
#!/usr/bin/python
from os.path import expanduser, join
import platform
import threading
import arrow
import upyun_api
home = expanduser("~")
def run_sync(periodic=False):
lastsynctime = None
if platform.node() == 'fbt127':
now = arrow.utcnow().timestamp
try:
with open('lastsynctime', 'r+') as f:
lastsynctime = f.readline().strip()
f.seek(0, 0)
f.write(str(now))
except IOError:
with open('lastsynctime', 'w') as f:
f.write(str(now))
lastsynctime = now
print("run sync: " + arrow.utcnow().format('YYYY-MM-DD HH:mm:ss ZZ'))
upyun_api.sync_folder(
join(home, 'latest_fbt_server_py', 'static/images'), '/static/images',
lastsynctime=int(lastsynctime)
)
if periodic:
threading.Timer(300, run_sync, (True, )).start()
if __name__ == '__main__':
run_sync(periodic=True)