Skip to content

Commit 7e066aa

Browse files
CopilotMishkatIT
andcommitted
Address final code review suggestions - add comments and named constants
Co-authored-by: MishkatIT <125080003+MishkatIT@users.noreply.github.com>
1 parent 5323502 commit 7e066aa

3 files changed

Lines changed: 13 additions & 5 deletions

File tree

‎manual_update.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,10 @@ def save_last_known_counts(stats):
6767
try:
6868
with open('last_known_counts.json', 'r') as f:
6969
last_known = json.load(f)
70-
except Exception:
71-
pass
70+
except (json.JSONDecodeError, IOError) as e:
71+
# Log the error but continue with default structure
72+
print(f"Warning: Could not load existing last_known_counts.json: {e}")
73+
print("Starting with fresh data structure.")
7274

7375
# Update with new stats
7476
for platform, count in stats.items():

‎quick_update.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,10 @@ def save_last_known_counts(stats):
4242
try:
4343
with open('last_known_counts.json', 'r') as f:
4444
last_known = json.load(f)
45-
except Exception:
46-
pass
45+
except (json.JSONDecodeError, IOError) as e:
46+
# Log the error but continue with default structure
47+
print(f"Warning: Could not load existing last_known_counts.json: {e}")
48+
print("Starting with fresh data structure.")
4749

4850
# Update with new stats
4951
for platform, count in stats.items():

‎update_stats.py‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def _load_last_known_counts(self):
3030
data = json.load(f)
3131
return data
3232
except FileNotFoundError:
33+
# File doesn't exist yet, will be created on first save
3334
pass
3435
except Exception as e:
3536
print(f"Warning: Could not load last known counts: {e}")
@@ -181,6 +182,9 @@ def get_atcoder(self):
181182

182183
def get_codechef(self):
183184
"""Fetch CodeChef statistics using web scraping."""
185+
# Maximum reasonable problem count to detect parsing errors
186+
MAX_REASONABLE_COUNT = 10000
187+
184188
try:
185189
url = "https://www.codechef.com/users/MishkatIT"
186190
html = self.fetch_url(url)
@@ -204,7 +208,7 @@ def get_codechef(self):
204208
if match:
205209
count = int(match.group(1))
206210
# Sanity check - CodeChef count should be reasonable
207-
if 0 < count < 10000:
211+
if 0 < count < MAX_REASONABLE_COUNT:
208212
print(f" Found using pattern: {pattern[:50]}...")
209213
return count
210214

0 commit comments

Comments
 (0)