Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 82662fc882 | |||
| cb11097664 | |||
| db6e7fd246 | |||
| af44323930 | |||
| 33540344b0 | |||
| 1958ec222f | |||
| f2d431ab84 | |||
| 31d06224b0 | |||
| 51d8bb9da9 | |||
| f3635b2458 | |||
| 962e0cb4de | |||
| 8948fcc78d |
5
.gitmodules
vendored
5
.gitmodules
vendored
@@ -1,3 +1,4 @@
|
||||
[submodule "jogobot"]
|
||||
path = jogobot
|
||||
url = ../jogobot
|
||||
path = jogobot
|
||||
url = git@github.com:golderweb/wiki-jogobot-core.git
|
||||
branch = test-v1
|
||||
|
||||
21
README.md
Normal file
21
README.md
Normal file
@@ -0,0 +1,21 @@
|
||||
# wiki-jogobot-charts
|
||||
This is a [Pywikibot](https://www.mediawiki.org/wiki/Manual:Pywikibot) based [Wikipedia Bot](https://de.wikipedia.org/wiki/Wikipedia:Bots)
|
||||
of [User:JogoBot](https://de.wikipedia.org/wiki/Benutzer:JogoBot) on the
|
||||
[German Wikipedia](https://de.wikipedia.org/wiki/Wikipedia:Hauptseite).
|
||||
|
||||
On [JogoBots wikipedia user page](https://de.wikipedia.org/wiki/Benutzer:JogoBot/Charts) a more detailed description can be found.
|
||||
|
||||
## Requirements
|
||||
* Python 3.4+ (at least it is only tested with those)
|
||||
* pywikibot-core 2.0
|
||||
* [jogobot-core module](https://github.com/golderweb/wiki-jogobot-core) used as submodule
|
||||
* [Isoweek module](https://pypi.python.org/pypi/isoweek)
|
||||
|
||||
## Bugs
|
||||
[wiki-jogobot-charts on fs.golderweb.de (de)](https://fs.golderweb.de/proj20)
|
||||
|
||||
## License
|
||||
GPLv3+
|
||||
|
||||
## Author Information
|
||||
Copyright 2016 Jonathan Golder <jonathan@golderweb.de>
|
||||
@@ -3,7 +3,7 @@
|
||||
#
|
||||
# __init__.py
|
||||
#
|
||||
# Copyright 2015 GOLDERWEB – Jonathan Golder <jonathan@golderweb.de>
|
||||
# Copyright 2016 Jonathan Golder <jonathan@golderweb.de>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
|
||||
29
charts.py
29
charts.py
@@ -11,7 +11,7 @@
|
||||
#
|
||||
# modified by:
|
||||
#
|
||||
# Copyright 2016 GOLDERWEB – Jonathan Golder <jonathan@golderweb.de>
|
||||
# Copyright 2016 Jonathan Golder <jonathan@golderweb.de>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -94,23 +94,38 @@ class ChartsBot( ):
|
||||
# Output Information
|
||||
jogobot.output( "Chartsbot invoked" )
|
||||
|
||||
# Set the edit summary message
|
||||
# Save pywikibot site object
|
||||
self.site = pywikibot.Site()
|
||||
self.summary = "Bot: Aktualisiere Übersichtsseite Nummer-eins-Hits"
|
||||
|
||||
# Define edit summary
|
||||
self.summary = jogobot.config["charts"]["edit_summary"].strip()
|
||||
|
||||
# Make sure summary starts with "Bot:"
|
||||
if not self.summary[:len("Bot:")] == "Bot:":
|
||||
self.summary = "Bot: " + self.summary.strip()
|
||||
|
||||
# Set locale to 'de_DE.UTF-8'
|
||||
locale.setlocale(locale.LC_ALL, 'de_DE.UTF-8')
|
||||
|
||||
def run(self):
|
||||
"""Process each page from the generator."""
|
||||
# Count skipped pages (redirect or missing)
|
||||
skipped = 0
|
||||
for page in self.generator:
|
||||
self.treat(page)
|
||||
if not self.treat(page):
|
||||
skipped += 1
|
||||
|
||||
if skipped:
|
||||
jogobot.output( "Chartsbot finished, {skipped} page(s) skipped"
|
||||
.format( skipped=skipped ) )
|
||||
else:
|
||||
jogobot.output( "Chartsbot finished successfully" )
|
||||
|
||||
def treat(self, page):
|
||||
"""Load the given page, does some changes, and saves it."""
|
||||
text = self.load(page)
|
||||
if not text:
|
||||
return
|
||||
return False
|
||||
|
||||
################################################################
|
||||
# NOTE: Here you can modify the text in whatever way you want. #
|
||||
@@ -127,6 +142,8 @@ class ChartsBot( ):
|
||||
if not self.save(text, page, self.summary, False):
|
||||
jogobot.output(u'Page %s not saved.' % page.title(asLink=True))
|
||||
|
||||
return True
|
||||
|
||||
def load(self, page):
|
||||
"""Load the text of the given page."""
|
||||
try:
|
||||
@@ -140,7 +157,7 @@ class ChartsBot( ):
|
||||
% page.title(asLink=True), "ERROR" )
|
||||
else:
|
||||
return text
|
||||
return None
|
||||
return False
|
||||
|
||||
def save(self, text, page, comment=None, minorEdit=True,
|
||||
botflag=True):
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#
|
||||
# countrylist.py
|
||||
#
|
||||
# Copyright 2015 GOLDERWEB – Jonathan Golder <jonathan@golderweb.de>
|
||||
# Copyright 2016 Jonathan Golder <jonathan@golderweb.de>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -34,6 +34,8 @@ from isoweek import Week
|
||||
import pywikibot
|
||||
import mwparserfromhell as mwparser
|
||||
|
||||
import jogobot
|
||||
|
||||
|
||||
class CountryList():
|
||||
"""
|
||||
@@ -131,6 +133,10 @@ class CountryList():
|
||||
# For easy detecting wether we have parsed self
|
||||
self.parsed = True
|
||||
|
||||
# Log parsed page
|
||||
jogobot.output( "Parsed revision {revid} of page [[{title}]]".format(
|
||||
revid=self.revid, title=self.page.title() ) )
|
||||
|
||||
def detect_belgian( self ):
|
||||
"""
|
||||
Detect wether current entry is on of the belgian (Belgien/Wallonien)
|
||||
@@ -278,6 +284,9 @@ missing!" )
|
||||
if self.entry.has( "Titel" ):
|
||||
self._titel_raw = self.entry.get("Titel").value
|
||||
|
||||
# Only use part before possible "<br"
|
||||
self.remove_lines(self._titel_raw)
|
||||
|
||||
# Remove possible ref-tags
|
||||
for ref in self._titel_raw.ifilter_tags(matches="ref"):
|
||||
self._titel_raw.remove( ref )
|
||||
@@ -350,6 +359,9 @@ missing!" )
|
||||
if self.entry.has( "Interpret" ):
|
||||
self._interpret_raw = self.entry.get("Interpret").value
|
||||
|
||||
# Only use part before possible "<br"
|
||||
self.remove_lines(self._interpret_raw)
|
||||
|
||||
# Remove possible ref-tags
|
||||
for ref in self._interpret_raw.ifilter_tags(matches="ref"):
|
||||
self._interpret_raw.remove( ref )
|
||||
@@ -452,6 +464,25 @@ missing!" )
|
||||
else:
|
||||
return str(keywords[0])
|
||||
|
||||
def remove_lines(self, wikicode):
|
||||
"""
|
||||
Removes linebreaks (<br>) and everything after them in given wikicode
|
||||
"""
|
||||
# Catch wrong typed param
|
||||
if not isinstance(wikicode, mwparser.wikicode.Wikicode):
|
||||
raise TypeError(str(type(self)) + "._remove_lines() expects " +
|
||||
"parameter 'wikicode' of type " +
|
||||
"'mwparserfromhell.wikicode.Wikicode', " +
|
||||
str(type(wikicode)) + " was given!")
|
||||
|
||||
# Find first linebreak
|
||||
br = next(wikicode.ifilter_tags(matches="br"), None)
|
||||
|
||||
# If there is one, get its position and slice nodes-list
|
||||
if br:
|
||||
brpos = wikicode.nodes.index(br)
|
||||
wikicode.nodes = wikicode.nodes[0:brpos]
|
||||
|
||||
def __str__( self ):
|
||||
"""
|
||||
Returns str repression for Object
|
||||
|
||||
2
jogobot
2
jogobot
Submodule jogobot updated: 2173f2984f...9131235b7b
@@ -3,7 +3,7 @@
|
||||
#
|
||||
# summarypage.py
|
||||
#
|
||||
# Copyright 2015 GOLDERWEB – Jonathan Golder <jonathan@golderweb.de>
|
||||
# Copyright 2016 Jonathan Golder <jonathan@golderweb.de>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -30,6 +30,8 @@ from datetime import datetime, timedelta
|
||||
# import pywikibot
|
||||
import mwparserfromhell as mwparser
|
||||
|
||||
import jogobot
|
||||
|
||||
from countrylist import CountryList, CountryListError
|
||||
|
||||
|
||||
@@ -145,6 +147,9 @@ class SummaryPageEntry():
|
||||
|
||||
# If list is from last year, replace year
|
||||
if (current_year - 1) in self.countrylist_wikilink.title:
|
||||
jogobot.output( "Trying to use new years list for [[{page}]]"
|
||||
.format( page=self.countrylist_wikilink.title ) )
|
||||
|
||||
self.countrylist_wikilink.title.replace( (current_year - 1),
|
||||
current_year )
|
||||
|
||||
@@ -159,6 +164,10 @@ class SummaryPageEntry():
|
||||
|
||||
# If list is from last year, replace year
|
||||
if (current_year ) in self.countrylist_wikilink.title:
|
||||
jogobot.output( "New years list for [[{page}]] does not " +
|
||||
"exist, fall back to old list!".format(
|
||||
page=self.countrylist_wikilink.title ) )
|
||||
|
||||
self.countrylist_wikilink.title.replace( current_year,
|
||||
(current_year - 1) )
|
||||
|
||||
|
||||
Reference in New Issue
Block a user