Skip to content

Commit

Permalink
Fix ruff lint.
Browse files Browse the repository at this point in the history
  • Loading branch information
emmiegit committed Jan 15, 2024
1 parent fc09063 commit 379f730
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 8 deletions.
2 changes: 1 addition & 1 deletion yellowstone/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

from .config import Config, getenv
from .exceptions import UnknownJobError
from .jobs import JobType, get_user, get_user_avatar, get_site, index_site_members
from .jobs import JobType, get_site, get_user, get_user_avatar, index_site_members
from .s3 import S3
from .types import Json
from .wikidot import Wikidot
Expand Down
12 changes: 10 additions & 2 deletions yellowstone/jobs/get_site.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@
"""

import logging
from typing import TYPE_CHECKING

from .. import JobType
from ..requests import site_home_raw
from ..wikidot import Wikidot

if TYPE_CHECKING:
from ..core import BackupDispatcher

logger = logging.getLogger(__name__)


Expand All @@ -33,7 +36,12 @@ def should_fetch() -> bool:
core.site_id_cache[site_slug] = site.id


def insert_site(*, database, wikidot: Wikidot) -> site_home_raw.SiteHomeData:
def insert_site(
site_slug: str,
*,
database,
wikidot: Wikidot,
) -> site_home_raw.SiteHomeData:
site = site_home_raw.get(site_slug, wikidot=wikidot)

database.add_site(
Expand Down
4 changes: 4 additions & 0 deletions yellowstone/jobs/get_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
"""

import logging
from typing import TYPE_CHECKING

from .. import JobType
from ..requests import user as user_data

if TYPE_CHECKING:
from ..core import BackupDispatcher

logger = logging.getLogger(__name__)


Expand Down
4 changes: 4 additions & 0 deletions yellowstone/jobs/get_user_avatar.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
"""

import logging
from typing import TYPE_CHECKING

from ..exceptions import JobFailed
from ..requests import user_avatar

if TYPE_CHECKING:
from ..core import BackupDispatcher

logger = logging.getLogger(__name__)


Expand Down
2 changes: 1 addition & 1 deletion yellowstone/jobs/index_site_members.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import logging
from typing import Optional

from ..core import BackupDispatcher
from .. import JobType
from ..core import BackupDispatcher
from ..requests import site_members

START_OFFSET = 1
Expand Down
13 changes: 9 additions & 4 deletions yellowstone/requests/site_home_raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@
import logging
import re
from dataclasses import dataclass
from typing import Optional
from typing import TYPE_CHECKING, Optional

from bs import BeautifulSoup

from ..scraper import download_html, find_element, make_soup, regex_extract
from ..wikidot import Wikidot

if TYPE_CHECKING:
pass

LANGUAGE_REGEX = re.compile(r"WIKIREQUEST\.info\.lang = '([^']+)';")
SITE_ID_REGEX = re.compile(r"WIKIREQUEST\.info\.siteId = (\d+);")
SITE_SLUG_REGEX = re.compile(r'WIKIREQUEST\.info\.siteUnixName = "([^"]+)";')
Expand Down Expand Up @@ -37,7 +42,7 @@ class SiteHomeData:
def get(site_slug: str, *, wikidot: Wikidot) -> SiteHomeData:
logger.info("Retrieving site home page for %s", site_slug)

url = wikidot.site_url(site_slug)
source = url = wikidot.site_url(site_slug)
html = download_html(url)

language = regex_extract(url, html, LANGUAGE_REGEX)[1]
Expand All @@ -49,7 +54,7 @@ def get(site_slug: str, *, wikidot: Wikidot) -> SiteHomeData:
assert site_slug == site_slug_ex, "site slug in scraped page doesn't match"

soup = make_soup(html)
name, tagline = get_site_tagline(source, soup)
name, tagline = get_site_titles(source, soup)
discussion_thread_id = get_discussion_thread_id(source, soup)

return SiteHomeData(
Expand All @@ -65,7 +70,7 @@ def get(site_slug: str, *, wikidot: Wikidot) -> SiteHomeData:
)


def get_site_taglines(source: str, soup: BeautifulSoup) -> tuple[str, str]:
def get_site_titles(source: str, soup: BeautifulSoup) -> tuple[str, str]:
logger.debug("Extracting page title and subtitle from %s", source)
header = find_element(source, soup, "div#header")
name = find_element(source, header, "h1 span").text
Expand Down

0 comments on commit 379f730

Please sign in to comment.