-
Notifications
You must be signed in to change notification settings - Fork 1
/
BlogSynchronize.py
48 lines (37 loc) · 1.23 KB
/
BlogSynchronize.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
import http.server as HTTP
import socketserver
import os
import time
import threading
import logging
PORT = 15622
Protocol = "HTTP/1.1"
git_origins = "https://github.com/zxy16305/Blog"
hexo_current_working_directory = "/root/applications/hexo/"
git_directory = "/root/applications/hexo/"
delay_git = 2
delay_hexo = 20
def git_and_hexo():
os.system(
"cd " + git_directory + " && git pull " + git_origins + " && hexo --cwd " + hexo_current_working_directory + " generate")
def git_pull():
os.system("cd " + git_directory + " && git pull " + git_origins)
# print("git pull")
t = threading.Timer(delay_hexo, hexo_generate)
t.start()
def hexo_generate():
# print("hexo generate")
os.system("hexo --cwd " + hexo_current_working_directory + " generate")
class myHandler(HTTP.BaseHTTPRequestHandler):
def do_POST(self):
if self.path == "/update":
print("com in post")
self.send_response(200)
self.end_headers()
self.wfile.write(bytes("OK", encoding="utf-8"))
t = threading.Timer(delay_git, git_and_hexo)
t.start()
return
with socketserver.TCPServer(("", PORT), myHandler) as httpd:
print("com in")
httpd.serve_forever()