-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsystem.py
33 lines (31 loc) · 943 Bytes
/
system.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
import os
import util
import requests
import json
import configparser
import time
@util.cmd
def start(**kwargs):
os.system("cd /opt/SubwayTraffic\nnohup python main.py >nohup 2>&1 &")
conf = configparser.ConfigParser()
conf.read("/opt/SubwayTrafficCommand/client.ini")
body = {
"email": conf.get("admin", "email"),
"password": conf.get("admin", "pwd")
}
body = json.dumps(body)
print("SubwayTraffic service starting... Please wait.")
time.sleep(3)
result = requests.post(data=body, **kwargs)
message = result.json()
code = message["code"]
if code == 200:
token = message["token"]
data = {"token": token}
data = json.dumps(data, indent=4)
with open("/opt/SubwayTrafficCommand/token.json", "w") as \
json_file:
json_file.write(data)
json_file.close()
else:
print("login admin user error:", message)