Skip to content

Commit

Permalink
Merge pull request #334 from re0wiki/dev
Browse files Browse the repository at this point in the history
multiple bug fixes and enhancements
  • Loading branch information
CCXXXI authored Jun 16, 2024
2 parents 414d740 + 38b6c82 commit 40acde1
Show file tree
Hide file tree
Showing 10 changed files with 144 additions and 121 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/re0wiki.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@

## Deployment

- **本项目**`git clone --depth 1 --recurse-submodules --shallow-submodules https://github.com/re0wiki/wiki-bot.git`
- **本项目**`git clone --recurse-submodules https://github.com/re0wiki/wiki-bot.git`
- **Python**[conda-forge/miniforge](https://github.com/conda-forge/miniforge#install)
- **requirements**`mamba env create -f environment.yml`
- **requirements**`mamba env create -yf environment.yml`
- [机器人密码 | Re:从零开始的异世界生活 Wiki | Fandom](https://rezero.fandom.com/zh/wiki/Special:BotPasswords)
- **用户配置文件**
1. [user-config.py#L17](./user-config.py#L17)
Expand Down
3 changes: 1 addition & 2 deletions environment.dev.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# mamba env create -f environment.dev.yml --force
# mamba env create -yf environment.dev.yml
name: re0wiki
channels: [conda-forge]
dependencies:
Expand All @@ -10,4 +10,3 @@ dependencies:
- -r pywikibot/requirements.txt
# dev
- git+https://github.com/ccxxxi/pywikibot
- black
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# mamba env create -f environment.yml --force
# mamba env create -yf environment.yml
name: re0wiki
channels: [conda-forge]
dependencies:
Expand Down
19 changes: 12 additions & 7 deletions families/re0_family.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
"""
This family file was auto-generated by generate_family_file.py script.
Configuration parameters:
url = https://rezero.fandom.com/zh
name = re0
Please do not commit this to the Git repository!
"""

from pywikibot import family


class Family(family.Family): # noqa: D101
"""Re0 family."""

name = "re0"
langs = {
Expand All @@ -20,9 +29,7 @@ class Family(family.Family): # noqa: D101
"uk": "rezero.fandom.com",
}

@staticmethod
def scriptpath(code):
"""The prefix used to locate scripts on this wiki."""
def scriptpath(self, code):
return {
"zh": "/zh",
"de": "/de",
Expand All @@ -38,9 +45,7 @@ def scriptpath(code):
"uk": "/uk",
}[code]

@staticmethod
def protocol(code):
"""The protocol to use to connect to the site."""
def protocol(self, code):
return {
"zh": "https",
"de": "https",
Expand Down
2 changes: 1 addition & 1 deletion jobs/re0_gallery.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from .jobs_ import CmdJob, add_job

add_job(CmdJob(["re0_gallery"]))
add_job(CmdJob(["re0_gallery", "-catr:图库"]))
2 changes: 1 addition & 1 deletion pywikibot
Submodule pywikibot updated 350 files
13 changes: 8 additions & 5 deletions scripts/re0_gallery.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
import regex as re
from pywikibot import Page
from pywikibot.cosmetic_changes import CosmeticChangesToolkit
from pywikibot.pagegenerators import AllpagesPageGenerator
from pywikibot.pagegenerators import GeneratorFactory
from tqdm import tqdm
import pywikibot

NESTED_TEMPLATE_REGEX = re.compile(
r"""
Expand All @@ -29,7 +30,11 @@

def sync_galleries():
"""Replace zh galleries with en galleries."""
for zh_page in tqdm(list(AllpagesPageGenerator(includeredirects=False))):

gen_factory = GeneratorFactory()
gen_factory.handle_args(pywikibot.handle_args())

for zh_page in tqdm(list(gen_factory.getCombinedGenerator())):
zh_page: Page

# get zh text
Expand Down Expand Up @@ -63,9 +68,7 @@ def sync_galleries():
len(zh_galleries),
)

# try to sync the page for 图库
if not zh_page.title().endswith("图库"):
continue
# try to sync the page
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:
Expand Down
Loading

0 comments on commit 40acde1

Please sign in to comment.