Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@finghine
Last active June 27, 2017 09:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save finghine/29e88868fd69e124c1cc5079d33c43ba to your computer and use it in GitHub Desktop.
Save finghine/29e88868fd69e124c1cc5079d33c43ba to your computer and use it in GitHub Desktop.
sync example python 文件同步示例
from watchdog.observers import Observer
from watchdog.events import *
import time
import sys
import subprocess
reload(sys)
sys.setdefaultencoding('utf-8')
class FileEventHandler(FileSystemEventHandler):
def __init__(self):
FileSystemEventHandler.__init__(self)
def on_modified(self, event):
filepath = event.src_path
if filepath.endswith("xx.txt"):
print "sync..."
subprocess.call(["sync.bat"])
print "sync over"
if __name__ == "__main__":
observer = Observer()
event_handler = FileEventHandler()
observer.schedule(event_handler,"C:/watchdog_test/example",True)
observer.start()
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
observer.stop()
observer.join()
# save to sync.bat
# tar -zcvf - xx.txt | openssl des3 -salt -k 123123 | dd of=xx.txt.des3
# set https_proxy=http://localhost:1080
# gdrive update 0BzqNJHAvF2Hta3dMYXE0NUNuRjQ xx.txt.des3
# gdrive in the dir
# need proxy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment