summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar klea2025-12-08 20:30:41 +0100
committerGravatar klea2025-12-08 20:37:48 +0100
commitae1b0e396fc74b61fd25abc3672170d110240b21 (patch)
treed21572b4c751c3322003acca6a05c05b908c22e6
parentmwrepl: update to work with pywikibot (diff)
signature
wikibot: use pywikibot instead of mwclient
-rw-r--r--wikibot/currentwarriorproject.py17
-rw-r--r--wikibot/inthemedia.py19
-rw-r--r--wikibot/urlteam.py17
-rw-r--r--wikibot/votesinswitzerland.py20
-rw-r--r--wikibot/wbmexclusions.py2
5 files changed, 34 insertions, 41 deletions
diff --git a/wikibot/currentwarriorproject.py b/wikibot/currentwarriorproject.py
index dff5557..2b2ae1e 100644
--- a/wikibot/currentwarriorproject.py
+++ b/wikibot/currentwarriorproject.py
@@ -1,8 +1,6 @@
-import mwclient
-import os
+import pywikibot
import requests
-
# Retrieve current project
def get_current_default_project():
response = requests.get('https://warriorhq.archiveteam.org/projects.json')
@@ -13,18 +11,17 @@ def get_current_default_project():
return p
return None
-
def default_project_to_wiki_text(project):
return '{{CurrentWarrior|' + project['name'] + '|' + project['title'] + '}}'
-
# Update the wiki page if necessary
def maybe_edit_wiki(pageText):
- site = mwclient.Site('wiki.archiveteam.org', path = '/')
- page = site.Pages['Main_Page/Current_Warrior_Project']
- if page.text() != pageText:
- site.login(os.environ['ATWIKIBOT_USERNAME'], os.environ['ATWIKIBOT_PASSWORD']) # Only log in when necessary
- page.save(pageText)
+ site = pywikibot.Site('en', 'ArchiveTeam')
+ page = pywikibot.Page(site, 'Main_Page/Current_Warrior_Project')
+ if page.text != pageText:
+ site.login() # Only log in when necessary
+ page.text = pageText
+ page.save("Obtained data from WarriorHQ file")
maybe_edit_wiki(default_project_to_wiki_text(get_current_default_project()))
diff --git a/wikibot/inthemedia.py b/wikibot/inthemedia.py
index 7712bfc..aa9e0cc 100644
--- a/wikibot/inthemedia.py
+++ b/wikibot/inthemedia.py
@@ -1,16 +1,14 @@
-import mwclient
-import os
-
+import pywikibot
def main():
- site = mwclient.Site('wiki.archiveteam.org', path = '/')
+ site = pywikibot.Site('en', 'ArchiveTeam')
# Retrieve full "In The Media" page
- mediaPage = site.Pages['In The Media']
+ mediaPage = pywikibot.Page(site, 'In The Media')
# Parse contents and extract first 10 entries
entries = []
- for line in mediaPage.text().split('\n'):
+ for line in mediaPage.text.split('\n'):
if not line:
continue
if line[0] == ';':
@@ -31,10 +29,11 @@ def main():
contentsStr = '\n'.join(contents)
# Update if necessary
- mainPage = site.Pages['Main Page/In The Media']
- if mainPage.text() != contentsStr:
- site.login(os.environ['ATWIKIBOT_USERNAME'], os.environ['ATWIKIBOT_PASSWORD']) # Only log in when necessary
- mainPage.save(contentsStr)
+ mainPage = pywikibot.Page(site, 'Main Page/In The Media')
+ if mainPage.text != contentsStr:
+ site.login() # Only log in when necessary
+ mainPage.text = contentsStr
+ mainPage.save("Updated from " + mediaPage.title(as_link=True))
main()
diff --git a/wikibot/urlteam.py b/wikibot/urlteam.py
index 746a5c0..f10d561 100644
--- a/wikibot/urlteam.py
+++ b/wikibot/urlteam.py
@@ -1,15 +1,13 @@
import collections
-import mwclient
+import pywikibot
import re
-import os
-
def main():
- site = mwclient.Site('wiki.archiveteam.org', path = '/')
+ site = pywikibot.Site('en', 'ArchiveTeam')
- page = site.Pages['URLTeam/Dead']
+ page = pywikibot.Page(site, 'URLTeam/Dead')
- entries = collections.deque(page.text().split('\n'))
+ entries = collections.deque(page.text.split('\n'))
# Identify blocks of URLs and sort them
entries.append(None) # Dummy entry at the end to trigger a last sorting if necessary
@@ -33,9 +31,10 @@ def main():
outputStr = '\n'.join(output)
# Update if necessary
- if page.text() != outputStr:
- site.login(os.environ['ATWIKIBOT_USERNAME'], os.environ['ATWIKIBOT_PASSWORD']) # Only log in when necessary
- page.save(outputStr)
+ if page.text != outputStr:
+ site.login() # Only log in when necessary
+ page.text = outputStr
+ page.save("Sorted url list")
main()
diff --git a/wikibot/votesinswitzerland.py b/wikibot/votesinswitzerland.py
index 3d738fc..3494276 100644
--- a/wikibot/votesinswitzerland.py
+++ b/wikibot/votesinswitzerland.py
@@ -1,7 +1,4 @@
-import mwclient
-import os
-import requests
-
+import pywikibot
BOT_OPEN_TAG = '<!-- Do not edit the list between this line and /bot; it is edited automatically by a bot. -->'
BOT_CLOSE_TAG = '<!-- /bot -->'
@@ -9,30 +6,31 @@ BOT_CLOSE_TAG = '<!-- /bot -->'
def get_archivebot_votes_in_switzerland_pages(site):
for page in site.allpages(prefix = 'ArchiveBot/Votes in Switzerland/'):
- if not page.name.endswith('/list'):
+ if not page.title().endswith('/list'):
yield page
def generate_page_list(site):
- return '\n'.join('* [[{}]]'.format(page.name) for page in get_archivebot_votes_in_switzerland_pages(site))
+ return '\n'.join('* {}'.format(page.title(as_link=True)) for page in get_archivebot_votes_in_switzerland_pages(site))
def maybe_edit_wiki(site, newList):
- page = site.Pages['Votes in Switzerland']
- oldText = page.text()
+ page = pywikibot.Page(site, 'Votes in Switzerland')
+ oldText = page.text
if BOT_OPEN_TAG + '\n' not in oldText or '\n' + BOT_CLOSE_TAG not in oldText:
print('Error: bot tag not found.')
return
prefix, remainder = oldText.split(BOT_OPEN_TAG + '\n', 1)
oldList, suffix = remainder.split('\n' + BOT_CLOSE_TAG, 1)
if oldList != newList:
- site.login(os.environ['ATWIKIBOT_USERNAME'], os.environ['ATWIKIBOT_PASSWORD'])
+ site.login()
pageText = prefix + BOT_OPEN_TAG + '\n' + newList + '\n' + BOT_CLOSE_TAG + suffix
- page.save(pageText)
+ page.text = pageText
+ page.save("Regenerated from subpages")
def main():
- site = mwclient.Site('wiki.archiveteam.org', path = '/')
+ site = pywikibot.Site('en', 'ArchiveTeam')
maybe_edit_wiki(site, generate_page_list(site))
diff --git a/wikibot/wbmexclusions.py b/wikibot/wbmexclusions.py
index 8bdc1a9..4c4c3c9 100644
--- a/wikibot/wbmexclusions.py
+++ b/wikibot/wbmexclusions.py
@@ -52,7 +52,7 @@ def handle_page(site, page):
page.save("Rendered from template")
def main():
- site = pywikibot.Site()
+ site = pywikibot.Site('en', 'ArchiveTeam')
for page in site.allpages(prefix = 'List of websites excluded from the Wayback Machine'):
handle_page(site, page)