From 172877410b3c7e8c5c0e66a1a6b592f25a0c2b71 Mon Sep 17 00:00:00 2001 From: David Lynch Date: Sun, 6 Mar 2022 10:42:39 -0600 Subject: [PATCH] Xenforo: if fetching a specific threadmark category, add it to the title Unless it's 1, since that's always "threadmarks" and the main story. Refs #79 --- sites/xenforo.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/sites/xenforo.py b/sites/xenforo.py index e3fd145..09790f4 100644 --- a/sites/xenforo.py +++ b/sites/xenforo.py @@ -69,6 +69,12 @@ class XenForo(Site): story = self._base_story(soup) + threadmark_categories = {} + # Note to self: in the source this is data-categoryId, but the parser + # in bs4 lowercases tags and attributes... + for cat in soup.find_all('a', attrs={'data-categoryid': True}): + threadmark_categories[int(cat['data-categoryid'])] = cat['title'] + if url.endswith('/reader'): reader_url = url elif soup.find('a', class_='readerToggle'): @@ -80,6 +86,10 @@ class XenForo(Site): reader_url = False if reader_url: + if m := re.search(r'\d+/(\d+)/reader', reader_url): + cat = int(m.group(1)) + if cat != 1 and cat in threadmark_categories: + story.title = f'{story.title} ({threadmark_categories[cat]})' idx = 0 while reader_url: reader_url = self._join_url(base, reader_url)