Below is a minimal, self‑contained Python module that
-
Opens https://beta.lmarena.ai/,
-
Looks for the first table on the page,
-
Tries to find a model whose name starts with o3 but is not any of the known “mini” variants,
-
Returns its current rank (row number) or None if not yet listed,
-
Invokes one of two user‑supplied callbacks:
• on_top(rank) → model found and it is #1
• on_not_top(rank) → model found but not #1
Feel free to swap those callbacks for whatever real action you want to take (Discord ping, HTTP request, etc.).
# lm_arena_checker.py
# Python ≥ 3.9
from __future__ import annotations
import re
import time
from dataclasses import dataclass
from typing import Callable, Optional
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
################################################################################
# User‑facing API
################################################################################
@dataclass(slots=True)
class O3Status:
found: bool # Was any O3 model found at all?
rank: Optional[int] # 1‑based rank, if found. None otherwise.
name: Optional[str] # The exact model name that was matched.
def check_o3(
*,
on_top: Callable[[O3Status], None],
on_not_top: Callable[[O3Status], None],
headless: bool = True,
timeout: int = 15,
) -> O3Status:
"""
Scrape LM Arena once, determine O3 rank, and run the proper callback.
Params
------
on_top(status) – called if O3 is present AND rank == 1
on_not_top(status) – called if O3 is present but rank > 1
(not called at all if O3 is absent)
headless – run Chrome headless or visible
timeout – max seconds to wait for the table
Returns
-------
An O3Status object (see dataclass above).
"""
# 1. Start a headless Chrome (undetected_chromedriver works too)
opts = Options()
if headless:
opts.add_argument('--headless=new')
opts.add_argument('--no-sandbox')
opts.add_argument('--disable-gpu')
driver = webdriver.Chrome(options=opts)
try:
driver.get("https://beta.lmarena.ai/")
# Wait (worst‑case) until the rows exist
end = time.time() + timeout
rows = []
while time.time() < end:
rows = driver.find_elements(By.CSS_SELECTOR, "table tbody tr")
if rows:
break
time.sleep(0.5)
else:
raise RuntimeError("Timed out waiting for LM Arena table.")
# 2. Regex to accept o3 but reject o3‑mini etc.
pattern = re.compile(r"\bo3(?![-_]mini)\S*", re.I)
for idx, tr in enumerate(rows, start=1): # idx == rank
name_cell = tr.find_element(By.CSS_SELECTOR, "td:nth-child(3)")
model_name = name_cell.text.strip()
if pattern.fullmatch(model_name):
status = O3Status(True, idx, model_name)
if idx == 1:
on_top(status)
else:
on_not_top(status)
return status
# Not found
status = O3Status(False, None, None)
return status
finally:
driver.quit()
################################################################################
# Example usage
################################################################################
if __name__ == "__main__":
def _top(s: O3Status):
print(f"🎉 O3 is already #1 ({s.name}) – nothing to do.")
def _not_top(s: O3Status):
print(f"⚠️ O3 found at rank {s.rank}: {s.name}. Triggering action...")
# TODO: integrate your own action here
# my_other_module.do_something()
stat = check_o3(on_top=_top, on_not_top=_not_top)
if not stat.found:
print("🙅 O3 not listed yet.")