-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodifyAIL.py
82 lines (73 loc) · 2.67 KB
/
modifyAIL.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
79
80
81
82
import sys
#print str(sys.argv[1])
AILPATH = str(sys.argv[1])
# -----------------------------------------------------------------------------
#
# UPDATE NAV_BAR
#
# -----------------------------------------------------------------------------
with open(AILPATH+"/var/www/templates/nav_bar.html", "r+") as f:
a = [x.rstrip() for x in f]
index = 0
foundStart = False
for item in a:
#if item.startswith("<div class=\"collapse navbar-collapse"):
if "collapse navbar-collapse" in item:
foundStart = True
elif (foundStart == True and "root.logout" in item):
a.insert(index-1, ' </li>')
a.insert(index-1, ' <a class="nav-link" id="page-options" href="{{ url_for(\'TwitterMon.TwitterMon_page\') }}" aria-disabled="true"><i class="fab fa-twitter"></i> Twitter Monitor</a>')
a.insert(index-1, ' <li class="nav-item mr-3">')
break
index += 1
# Go to start of file and clear it
f.seek(0)
f.truncate()
# Write each line back
for line in a:
f.write(line + "\n")
# -----------------------------------------------------------------------------
#
# UPDATE LAUNCH.SH
#
# -----------------------------------------------------------------------------
with open(AILPATH+"/bin/LAUNCH.sh", "r+") as f:
a = [x.rstrip() for x in f]
index = 0
foundStart = False
for item in a:
if item.startswith("function launching_scripts"):
foundStart = True
elif (foundStart == True and item.startswith("}")):
a.insert(index, ' screen -S "Script_AIL" -X screen -t "TwitterAnalyzer" bash -c "cd ${AIL_BIN}; ${ENV_PY} ./TwitterAnalyzer.py; read x"')
a.insert(index, ' sleep 0.1')
break
index += 1
# Go to start of file and clear it
f.seek(0)
f.truncate()
# Write each line back
for line in a:
f.write(line + "\n")
# -----------------------------------------------------------------------------
#
# UPDATE MODULES.CFG
#
# -----------------------------------------------------------------------------
with open(AILPATH+"/bin/packages/modules.cfg", "r+") as f:
a = [x.rstrip() for x in f]
index = 0
foundStart = False
for item in a:
if item.startswith("[SentimentAnalysis]"):
a.insert(index, '\n')
a.insert(index, 'subscribe = Redis_Global')
a.insert(index, '[TwitterAnalyzer]')
break
index += 1
# Go to start of file and clear it
f.seek(0)
f.truncate()
# Write each line back
for line in a:
f.write(line + "\n")