Last active
March 25, 2026 19:05
-
-
Save InfiniteCoder01/380568a476eb0cf344dcd959fc2e46df to your computer and use it in GitHub Desktop.
gepar.do table tracker
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import requests | |
| import time | |
| while True: | |
| try: | |
| response = requests.get("https://olimpiada.gepar.do/") | |
| response.raise_for_status() | |
| with open(time.strftime('%Y-%m-%d_%H.%M.%S.html'), 'wb') as f: | |
| f.write(response.content) | |
| print(f"Downloaded the webpage at {time.strftime('%Y-%m-%d %H:%M:%S')}") | |
| except Exception as e: | |
| print(f"Error downloading: {e}") | |
| time.sleep(60 * 5 - 0.5) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os | |
| import re | |
| from bs4 import BeautifulSoup | |
| from collections import defaultdict | |
| def parse(path): | |
| with open(path, 'r', encoding='utf-8') as f: | |
| soup = BeautifulSoup(f, 'html.parser') | |
| return data | |
| state = {} | |
| changes = [] | |
| for f in sorted(os.listdir('.')): | |
| if not f.endswith('.html'): continue | |
| timestamp = f[:-5] | |
| print(f'processing [{timestamp}]') | |
| with open(f, 'r', encoding='utf-8') as f: | |
| soup = BeautifulSoup(f, 'html.parser') | |
| table = soup.find('table', class_='standings') | |
| assert table | |
| rows = table.find_all('tr') | |
| for row in rows[1:]: # skip header | |
| cols = row.find_all('td') | |
| if not cols or 'full-head' in row.get('class', []): | |
| continue | |
| try: | |
| login = cols[1].text.strip() | |
| rank = int(cols[0].text.strip()) | |
| data = {} | |
| names = ['A1', 'B1', 'C1', 'D1'] | |
| for i, td in enumerate(cols[2:-1]): | |
| data[names[i]] = float(td.text.strip()) | |
| if not login in state: state[login] = {} | |
| for k, v in data.items(): | |
| if not k in state[login] or state[login][k] != v: | |
| changes.append({ | |
| 'login': login, | |
| 'task': k, | |
| 'timestamp': timestamp, | |
| 'points': v, | |
| 'rank': rank, | |
| }) | |
| state[login] = data | |
| except Exception: | |
| continue # skip weird rows like 'Full solutions' | |
| print('writing data') | |
| keys = ['name', 'at', 'from', 'to', 'rank'] | |
| with open('data.txt', 'w') as f: | |
| for data in sorted(changes, key=lambda data: data['timestamp']): | |
| f.write(f'[{data['timestamp']}] {data['login']} submitted {data['task']}, got {data['points']} (rank {data['rank']})\n') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment