Skip to content

Commit

Permalink
Strip out crap after karma level.
Browse files Browse the repository at this point in the history
  • Loading branch information
emmiegit committed Jan 15, 2024
1 parent 71ed151 commit 2d6d002
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion yellowstone/requests/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@
import logging
import re
from dataclasses import dataclass
from datetime import datetime
from datetime import datetime, date
from typing import Optional

from bs4 import Tag

from ..scraper import ScrapingError, make_soup, regex_extract, find_element, get_entity_date
from ..utils import chunks
from ..wikidot import Wikidot

KARMA_LEVEL_STRIP_REGEX = re.compile(r"([\w ]+?) *\t.*?")
USER_SLUG_REGEX = re.compile(r"https?://www\.wikidot\.com/user:info/([^/]+)")

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -93,6 +96,11 @@ def is_wikidot_pro(value: str) -> bool:


def karma_level(value: str) -> int:
# Strip out only the relevant level
match = KARMA_LEVEL_STRIP_REGEX.match(value)
assert match is not None, "No match for stripping out karma level data"

# Return the equivalent integer value
logger.debug("Extracting karma level from description '%s'", value)
match value:
case "none":
Expand Down

0 comments on commit 2d6d002

Please sign in to comment.