Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(gallery): improve sync #322

Merged
merged 5 commits into from
Jun 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions scripts/re0_gallery.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
)

gallery_pattern = re.compile(r"<gallery[^>]*>.*?</gallery>", re.DOTALL)
tabber_pattern = re.compile(r"<tabber>.*?</tabber>", re.DOTALL)
page_pattern = re.compile(r"(?<=}}).*?(?=\[\[)", re.DOTALL)


def sync_galleries():
Expand All @@ -33,12 +33,12 @@ def sync_galleries():
zh_page: Page

# get zh text
zh_text = zh_page.text
zh_raw_text = zh_text = zh_page.text

# get en text
for link in zh_page.iterlanglinks():
if link.site.code == "en":
en_text: str = Page(link).text
en_raw_text = en_text = Page(link).text
break
else:
logging.debug("no en page for %s", zh_page.title())
Expand All @@ -63,18 +63,19 @@ def sync_galleries():
len(zh_galleries),
)

# try to sync the tabber for 图库
# try to sync the page for 图库
if not zh_page.title().endswith("图库"):
continue
en_tabbers: list[str] = tabber_pattern.findall(en_text)
if len(en_tabbers) == 0:
logging.warning("no en tabber for %s", zh_page.title())
en_pages: list[str] = page_pattern.findall(en_raw_text)
zh_pages: list[str] = page_pattern.findall(zh_raw_text)
if len(en_pages) != 1:
logging.warning("en page format mismatch for %s", zh_page.title())
continue
if len(en_tabbers) > 1:
logging.warning("multiple en tabbers for %s", zh_page.title())
if len(zh_pages) != 1:
logging.warning("zh page format mismatch for %s", zh_page.title())
continue
is_sync_tabber = True
zh_text = tabber_pattern.sub(en_tabbers[0], zh_text)
zh_text = page_pattern.sub(en_pages[0], zh_raw_text)

# check galleries counts again
zh_galleries: list[str] = gallery_pattern.findall(zh_text)
Expand Down
2 changes: 1 addition & 1 deletion user-fixes.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def match_to_yyyymmdd(mouth: int, match: re.Match) -> str:
("Daisanshou", "第3章"),
("Daiyonshou", "第4章"),
("Anthology", "官方同人精选集"),
("Games", "游戏"),
("Games?", "游戏"),
("-Infinity", "INFINITY"),
("The Prophecy of the Throne", "虚假的王选候补"),
(r"Misc(ellaneous|\.)?", "其他"),
Expand Down