-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpy_viewer_count.py
135 lines (96 loc) · 3.65 KB
/
py_viewer_count.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
from copy import copy
from time import sleep
from functions import *
import copy
constants_2 = ReadFile("constants.txt")
WriteFile("comms_args_list.txt", "normal")
def StartSave(channel, comms_info):
print("start of saving", channel)
f_n = comms_info[0]
date_time = comms_info[1]
print("BEFORE start of thread")
args_list = [f_n, channel, date_time]
# process = Process(target=GetWebData, args=(args_list,))
# process.start()
WriteFile("comms_args_list.txt", args_list)
while True:
try:
while ReadFile("comms_args_list.txt") != "normal":
print("VC waiting for thread to start")
sleep(0.5)
break
except:
print("ERR IN READING FILE COMMS ARGS LIST")
sleep(0.5)
while True:
try:
r = ReadFile("comms_args_list.txt")
if r != "normal":
print("VC waiting for thread to start")
sleep(0.5)
else:
break
except:
sleep(0.2)
print("VC Back to normal")
def WaitConfirmDataSaved():
comms = ReadFile("comms_need_save_view_count.txt")
while comms[0] == "sent to js":
print("waiting for app static to save")
sleep(0.4)
comms = ReadFile("comms_need_save_view_count.txt")
if comms[0] == "Failed save requirement":
return "Failed save requirement"
return comms[1]
WriteFile("comms_need_save_view_count.txt", ["normal", []])
view_count_info = {}
processes = []
live_info = {channel : False for channel in constants_2["channels"] }
prev_live_info = {channel : False for channel in constants_2["channels"] }
need_save_d = {channel : False for channel in constants_2["channels"] }
saving_bool = False
TCT_max = 12 # 15 * 12 = 3mins
TCT_counter = 0
need_to_reset = False
while True:
#print(TCT_counter)
#print("in main loop")
for channel in constants_2["channels"]:
if TCT_counter % TCT_max == 0:
is_live = SaveTTVC(channel, True)
need_to_reset = True
else:
is_live = SaveTTVC(channel, False)
live_info[channel] = is_live
#print(channel, live_info[channel], prev_live_info[channel])
if prev_live_info[channel] and not live_info[channel]:
saving_bool = True
need_save_d[channel] = True
if not prev_live_info[channel] and live_info[channel]:
print("STREAM JUST STARTED", channel)
#ResetTTVC(channel)
if saving_bool:
WriteFile("comms_need_save_view_count.txt", ["sent to js", need_save_d])
comms_info = WaitConfirmDataSaved()
if comms_info == "Failed save requirement":
print("Failed save requirement")
else:
for channel in constants_2["channels"]:
if need_save_d[channel]:
StartSave(channel, comms_info[channel])
need_save_d[channel] = False
saving_bool = False
WriteFile("comms_need_save_view_count.txt", ["normal", []])
#print("end of loop")
TCT_counter += 1
printing_live_info = []
for channel in live_info.keys():
if live_info[channel]:
printing_live_info.append(channel)
print("live: ", printing_live_info)
prev_live_info = copy.deepcopy(live_info)
if need_to_reset:
print("3min mark")
TCT_counter = 1
need_to_reset = False
sleep(constants_2["update_time"])