-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontroller.py
78 lines (56 loc) · 1.45 KB
/
controller.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
73
74
75
76
77
78
from os import system
from subprocess import Popen as run
import json
def getData():
with open('/tmp/whatsAuto/controller.json', 'r') as f:
data = json.load(f)
return data
def runController():
data = {"session":"loggedIn", "status":"running"}
with open('/tmp/whatsAuto/controller.json', 'w') as f:
json.dump(data, f)
print("Logged In")
run([
'xterm',
'-T',
'Whatsapp Controller',
'-e',
'python3',
'/tmp/whatsAuto/controller.py',
'&&',
'sleep',
'10'
])
return
def createAndRun():
system('rm -rf /tmp/whatsAuto; mkdir /tmp/whatsAuto')
controller = """
import json
print("Whatsapp controller...")
def getData():
with open('/tmp/whatsAuto/controller.json', 'r') as f:
data = json.load(f)
return data
while True:
command = input(">> ")
if 'logout' in command.lower():
data = {"session":"loggedOut"}
with open('/tmp/whatsAuto/controller.json', 'w') as f:
json.dump(data, f)
print("Logged out")
elif 'status' in command.lower():
status = getData()['session']
print(status)
elif 'exit' in command.lower():
data = {"status":"quit"}
with open('/tmp/whatsAuto/controller.json', 'w') as f:
json.dump(data, f)
print("Logged out")
exit("🚫 Bye")
break
else:
print("Not a command")
"""
with open('/tmp/whatsAuto/controller.py', 'w') as f:
f.write(controller)
runController()