-
Notifications
You must be signed in to change notification settings - Fork 0
/
github_updater.py
72 lines (55 loc) · 2.74 KB
/
github_updater.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
from flask import Flask, request
import sys, json, subprocess, os
from sys import executable
app = Flask(__name__)
users=['DoctorDib', 'MidgetJake']
def update_server(name):
# Checks commited username pull.
if name in str(users):
print "======================================================================="
print "DOWNLOADING NEW UPDATE"
print "======================================================================="
# Kill everything with the keyword 'server.js'
subprocess.call("pkill -9 node", shell=True)
os.chdir("/projects/PreCureChat")
# Pulls latest files of GitHub
subprocess.call("git pull origin master", shell=True)
# Launches new code.
print "======================================================================="
print "GITHUB_UPDATER - UPDATE SUCCESSFUL"
print "======================================================================="
subprocess.Popen(["node", "server.js", ">", "out.log", "&", "disown"])
# Allows me to print to the terminal for debugging
sys.stdout.flush()
# Returns a code
return 'Successful'
else:
return 'User authentication denied'
@app.route('/',methods=['POST'])
def foo():
print "======================================================================="
print "NOTICE - LOG"
print "======================================================================="
data = json.loads(request.data)
print "Name: {}".format(data['commits'][0]['author']['name'])
print "Username: {}".format(data['commits'][0]['author']['username'])
print "Email: {}".format(data['commits'][0]['author']['email'])
print "-------------------------------------------------------------"
print "URL: {}".format(data['commits'][0]['url'])
print "Message: {}".format(data['commits'][0]['message'])
print "Date/Time: {}".format(data['commits'][0]['timestamp'])
print "-------------------------------------------------------------"
print "Added: {}".format(data['commits'][0]['added'])
print "-------------------------------------------------------------"
print "Removed: {}".format(data['commits'][0]['removed'])
print "-------------------------------------------------------------"
print "Modified: {}".format(data['commits'][0]['modified'])
name = data['commits'][0]['author']['username']
return update_server(name)
def mainSetup():
update_server('DoctorDib')
print "======================================================================="
print "GITHUB_UPDATER - LAUNCHED"
print "======================================================================="
app.run(host= 'precure.ddns.net', port=6000, debug=False)
mainSetup()