Terry Zhuo
commited on
Commit
·
c28a31b
1
Parent(s):
f5ae479
update
Browse files- azure_count_ip_data.py +28 -16
azure_count_ip_data.py
CHANGED
@@ -139,30 +139,42 @@ def get_file_data(content: str) -> Tuple[Optional[str], Optional[str], bool]:
|
|
139 |
# Early check if IP is in whitelist
|
140 |
ip_in_whitelist = ip in WHITELIST_IPS
|
141 |
|
142 |
-
#
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
148 |
# Only try to get username if the key exists
|
149 |
-
if 'username' in
|
150 |
-
username =
|
151 |
|
152 |
-
feedback =
|
153 |
|
154 |
# Check vote conditions: type is vote, feedback has 6 items, and at least 4 lines (2 rounds of chat)
|
|
|
|
|
155 |
vote_conditions_met = (
|
156 |
isinstance(feedback, dict) and
|
157 |
len(feedback) == 6 and
|
158 |
-
len(
|
159 |
)
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
except (json.JSONDecodeError, TypeError):
|
164 |
-
username = None
|
165 |
-
vote_conditions_met = False
|
166 |
|
167 |
# Check if username is in whitelist (if username exists)
|
168 |
username_in_whitelist = username in WHITELIST_USERNAMES if username else False
|
|
|
139 |
# Early check if IP is in whitelist
|
140 |
ip_in_whitelist = ip in WHITELIST_IPS
|
141 |
|
142 |
+
# Find the vote line (if any)
|
143 |
+
username = None
|
144 |
+
vote_conditions_met = False
|
145 |
+
vote_line_index = -1
|
146 |
+
|
147 |
+
# Search for the vote line
|
148 |
+
for i, line in enumerate(lines):
|
149 |
+
try:
|
150 |
+
line_data = json.loads(line)
|
151 |
+
if line_data.get('type') == 'vote':
|
152 |
+
vote_line_index = i
|
153 |
+
break
|
154 |
+
except json.JSONDecodeError:
|
155 |
+
continue
|
156 |
+
|
157 |
+
# If we found a vote line, check conditions and get username
|
158 |
+
if vote_line_index >= 0:
|
159 |
+
try:
|
160 |
+
vote_line_data = json.loads(lines[vote_line_index])
|
161 |
+
|
162 |
# Only try to get username if the key exists
|
163 |
+
if 'username' in vote_line_data:
|
164 |
+
username = vote_line_data.get('username')
|
165 |
|
166 |
+
feedback = vote_line_data.get('feedback')
|
167 |
|
168 |
# Check vote conditions: type is vote, feedback has 6 items, and at least 4 lines (2 rounds of chat)
|
169 |
+
# Only count lines up to and including the vote line
|
170 |
+
relevant_lines = lines[:vote_line_index + 1]
|
171 |
vote_conditions_met = (
|
172 |
isinstance(feedback, dict) and
|
173 |
len(feedback) == 6 and
|
174 |
+
len(relevant_lines) >= 4
|
175 |
)
|
176 |
+
except (json.JSONDecodeError, TypeError):
|
177 |
+
pass
|
|
|
|
|
|
|
|
|
178 |
|
179 |
# Check if username is in whitelist (if username exists)
|
180 |
username_in_whitelist = username in WHITELIST_USERNAMES if username else False
|