update 'match.lastindex' usage

This commit is contained in:
Mike Fährmann
2025-06-18 16:58:25 +02:00
parent 41191bb60a
commit b0580aba86
16 changed files with 126 additions and 219 deletions

View File

@@ -33,16 +33,9 @@ class JschanThreadExtractor(JschanExtractor):
pattern = BASE_PATTERN + r"/([^/?#]+)/thread/(\d+)\.html"
example = "https://94chan.org/a/thread/12345.html"
def __init__(self, match):
JschanExtractor.__init__(self, match)
index = match.lastindex
self.board = match[index-1]
self.thread = match[index]
def items(self):
url = "{}/{}/thread/{}.json".format(
self.root, self.board, self.thread)
thread = self.request(url).json()
url = f"{self.root}/{self.groups[-2]}/thread/{self.groups[-1]}.json"
thread = self.request_json(url)
thread["threadId"] = thread["postId"]
posts = thread.pop("replies", ())
@@ -53,7 +46,7 @@ class JschanThreadExtractor(JschanExtractor):
thread.update(post)
thread["count"] = len(files)
for num, file in enumerate(files):
url = self.root + "/file/" + file["filename"]
url = f"{self.root}/file/{file['filename']}"
file.update(thread)
file["num"] = num
file["siteFilename"] = file["filename"]
@@ -68,14 +61,10 @@ class JschanBoardExtractor(JschanExtractor):
r"(?:/index\.html|/catalog\.html|/\d+\.html|/?$)")
example = "https://94chan.org/a/"
def __init__(self, match):
JschanExtractor.__init__(self, match)
self.board = match[match.lastindex]
def items(self):
url = "{}/{}/catalog.json".format(self.root, self.board)
for thread in self.request(url).json():
url = "{}/{}/thread/{}.html".format(
self.root, self.board, thread["postId"])
board = self.groups[-1]
url = f"{self.root}/{board}/catalog.json"
for thread in self.request_json(url):
url = f"{self.root}/{board}/thread/{thread['postId']}.html"
thread["_extractor"] = JschanThreadExtractor
yield Message.Queue, url, thread