Skip to content

Commit

Permalink
Xenforo: if fetching a specific threadmark category, add it to the title
Browse files Browse the repository at this point in the history
Unless it's 1, since that's always "threadmarks" and the main story.

Refs #79
  • Loading branch information
kemayo committed Mar 6, 2022
1 parent 64d97b0 commit 1728774
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions sites/xenforo.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ def extract(self, url):

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'):
Expand All @@ -80,6 +86,10 @@ def extract(self, url):
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)
Expand Down

0 comments on commit 1728774

Please sign in to comment.