Internal Service β This is not an HTTP endpoint. Itβs called by the ranking-score route.
Purpose
Checks if a URL already has a score in the database. If yes, returns it. If no, generates a new score (32-49) and saves it.
Function Signature
async def get_or_create_ranking_score(website_url: str) -> int
Parameters
| Parameter | Type | Description |
|---|
website_url | str | The URL to look up or create a score for |
Returns
int - The ranking score (32-49 for new URLs, or existing stored score)
Logic Flow
Why 32-49?
The score range is intentionally low to:
- Show visitors they have βroom to improveβ
- Create urgency to sign up
- Leave headroom for competitor scores (which are always higher)
async def get_or_create_ranking_score(website_url: str) -> int:
await ensure_initialized()
if not supabase_ranking:
return random.randint(32, 49)
try:
existing = await supabase_ranking.table("pre_payment_rankings") \
.select("score").eq("website_url", website_url).execute()
if existing.data and len(existing.data) > 0:
return int(existing.data[0]["score"])
new_score = random.randint(32, 49)
await supabase_ranking.table("pre_payment_rankings").insert({
"website_url": website_url,
"score": new_score,
}).execute()
return new_score
except Exception as e:
return random.randint(32, 49) # Fallback
Error Handling
On database errors, falls back to generating a random score without saving. This ensures the endpoint always returns a response.