-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- give it a try as nightly run
- Loading branch information
Showing
10 changed files
with
182 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,24 @@ | ||
# EditorConfig is awesome: https://EditorConfig.org | ||
|
||
# top-most EditorConfig file | ||
root = true | ||
|
||
# Unix-style newlines with a newline ending every file | ||
[*] | ||
indent_style = space | ||
trim_trailing_whitespace = true | ||
end_of_line = lf | ||
charset = utf-8 | ||
|
||
# 4 space indentation | ||
[*.py] | ||
indent_size = 4 | ||
max_line_length = 119 | ||
insert_final_newline = true | ||
|
||
[*.json] | ||
indent_size = 2 | ||
|
||
# Tab indentation (no size specified) | ||
[Makefile] | ||
indent_style = tab | ||
|
||
# Matches the exact files either package.json or .travis.yml | ||
[config.yml] | ||
indent_size = 2 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
from datetime import datetime, timedelta | ||
|
||
from pywikibot import Site, Page | ||
|
||
from tools.bots import BotException | ||
from tools.bots.pi import CanonicalBot | ||
from tools.petscan import PetScan | ||
|
||
|
||
class Protect(CanonicalBot): | ||
def __init__(self, wiki, debug): | ||
CanonicalBot.__init__(self, wiki, debug, log_to_wiki=False) | ||
self.timeout: timedelta = timedelta(hours=2) | ||
|
||
def __enter__(self): | ||
super().__enter__() | ||
if not self.data: | ||
self.logger.warning("Try to get the deprecated data back.") | ||
try: | ||
self.data.get_deprecated() | ||
except BotException: | ||
self.logger.warning("There isn't deprecated data to reload.") | ||
return self | ||
|
||
@staticmethod | ||
def _prepare_searcher() -> PetScan: | ||
searcher = PetScan() | ||
searcher.add_positive_category("Fertig") | ||
searcher.add_negative_category("Korrigiert") | ||
searcher.add_negative_category("Unkorrigiert") | ||
searcher.add_negative_category("Unvollständig") | ||
searcher.set_sort_criteria("date") | ||
searcher.set_sortorder_decending() | ||
searcher.set_search_depth(1) | ||
searcher.set_timeout(120) | ||
searcher.last_change_after(datetime(year=2022, month=9, day=3)) | ||
return searcher | ||
|
||
def task(self) -> bool: | ||
searcher = self._prepare_searcher() | ||
self.logger.info(str(searcher)) | ||
lemma_list = searcher.get_combined_lemma_list(self.data) | ||
print(len(lemma_list)) | ||
for idx, lemma_str in enumerate(lemma_list): | ||
self.data[lemma_str] = datetime.now().strftime("%Y%m%d%H%M%S") | ||
lemma = Page(self.wiki, lemma_str) | ||
self.logger.debug(f"check lemma {lemma.title()} for protection") | ||
if not lemma.protection(): | ||
self.logger.debug(f"protect lemma {lemma.title()}") | ||
lemma.protect(reason="Schutz fertiger Seiten", | ||
protections={'move': 'autoconfirmed', 'edit': 'autoconfirmed'}) | ||
if self._watchdog(): | ||
self.logger.info(f"checked {idx} lemmas") | ||
break | ||
return True | ||
|
||
|
||
# PYWIKIBOT_DIR=/home/esommer/.pywikibot_protect | ||
|
||
if __name__ == "__main__": | ||
WS_WIKI = Site(code="de", fam="wikisource", user="THEprotectIT") | ||
with Protect(wiki=WS_WIKI, debug=False) as bot: | ||
bot.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from unittest import TestCase, mock | ||
|
||
|
||
class TestProtect(TestCase): | ||
def setUp(self): | ||
self.petscan_patcher = mock.patch("service.protect.PetScan") | ||
self.petscan_mock = self.petscan_patcher.start() | ||
self.run_mock = mock.Mock() | ||
self.petscan_mock.return_value = mock.Mock(run=self.run_mock) | ||
self.addCleanup(mock.patch.stopall) | ||
|
||
def tearDown(self): | ||
mock.patch.stopall() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.