Compare commits
18 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 90c4098046 | |||
| 7bc4f546f8 | |||
| 3fb86abac5 | |||
| 871cbccc72 | |||
| e61408f877 | |||
| e6ef20f0a4 | |||
| 5267966fa8 | |||
| 0b17998484 | |||
| cb11097664 | |||
| af44323930 | |||
| 33540344b0 | |||
| 1958ec222f | |||
| f2d431ab84 | |||
| 31d06224b0 | |||
| 51d8bb9da9 | |||
| f3635b2458 | |||
| 962e0cb4de | |||
| 8948fcc78d |
3
.gitmodules
vendored
3
.gitmodules
vendored
@@ -1,3 +0,0 @@
|
|||||||
[submodule "jogobot"]
|
|
||||||
path = jogobot
|
|
||||||
url = ../jogobot
|
|
||||||
43
README.md
Normal file
43
README.md
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
# 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
|
||||||
|
* python3.4+
|
||||||
|
|
||||||
|
|
||||||
|
* pywikibot-core
|
||||||
|
|
||||||
|
|
||||||
|
The libraries above need to be installed and configured manualy considering [documentation of pywikibot-core](https://www.mediawiki.org/wiki/Manual:Pywikibot).
|
||||||
|
|
||||||
|
* mwparserfromhell
|
||||||
|
* isoweek
|
||||||
|
* [jogobot-core module](https://git.golderweb.de/wiki/jogobot)
|
||||||
|
|
||||||
|
Those can be installed using pip and the _requirements.txt_ file provided with this packet
|
||||||
|
|
||||||
|
pip install -r requirements.txt
|
||||||
|
|
||||||
|
## Versions
|
||||||
|
|
||||||
|
* v1.3
|
||||||
|
- jogobot module not longer included
|
||||||
|
* v1.2
|
||||||
|
- improved repo structure
|
||||||
|
* v1.1
|
||||||
|
- Cut Titel and Interpret on first linebreak
|
||||||
|
* v1.0
|
||||||
|
- first stable release
|
||||||
|
|
||||||
|
## Bugs
|
||||||
|
[jogobot-charts Issues](https://git.golderweb.de/wiki/jogobot-charts/issues)
|
||||||
|
|
||||||
|
## License
|
||||||
|
GPLv3+
|
||||||
|
|
||||||
|
## Author Information
|
||||||
|
Copyright 2018 Jonathan Golder <jonathan@golderweb.de>
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
#
|
#
|
||||||
# __init__.py
|
# __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
|
# 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
|
# 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:
|
# modified by:
|
||||||
#
|
#
|
||||||
# Copyright 2016 GOLDERWEB – Jonathan Golder <jonathan@golderweb.de>
|
# Copyright 2017 Jonathan Golder <jonathan@golderweb.de>
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
@@ -94,23 +94,38 @@ class ChartsBot( ):
|
|||||||
# Output Information
|
# Output Information
|
||||||
jogobot.output( "Chartsbot invoked" )
|
jogobot.output( "Chartsbot invoked" )
|
||||||
|
|
||||||
# Set the edit summary message
|
# Save pywikibot site object
|
||||||
self.site = pywikibot.Site()
|
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'
|
# Set locale to 'de_DE.UTF-8'
|
||||||
locale.setlocale(locale.LC_ALL, 'de_DE.UTF-8')
|
locale.setlocale(locale.LC_ALL, 'de_DE.UTF-8')
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
"""Process each page from the generator."""
|
"""Process each page from the generator."""
|
||||||
|
# Count skipped pages (redirect or missing)
|
||||||
|
skipped = 0
|
||||||
for page in self.generator:
|
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):
|
def treat(self, page):
|
||||||
"""Load the given page, does some changes, and saves it."""
|
"""Load the given page, does some changes, and saves it."""
|
||||||
text = self.load(page)
|
text = self.load(page)
|
||||||
if not text:
|
if not text:
|
||||||
return
|
return False
|
||||||
|
|
||||||
################################################################
|
################################################################
|
||||||
# NOTE: Here you can modify the text in whatever way you want. #
|
# 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):
|
if not self.save(text, page, self.summary, False):
|
||||||
jogobot.output(u'Page %s not saved.' % page.title(asLink=True))
|
jogobot.output(u'Page %s not saved.' % page.title(asLink=True))
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
def load(self, page):
|
def load(self, page):
|
||||||
"""Load the text of the given page."""
|
"""Load the text of the given page."""
|
||||||
try:
|
try:
|
||||||
@@ -140,7 +157,7 @@ class ChartsBot( ):
|
|||||||
% page.title(asLink=True), "ERROR" )
|
% page.title(asLink=True), "ERROR" )
|
||||||
else:
|
else:
|
||||||
return text
|
return text
|
||||||
return None
|
return False
|
||||||
|
|
||||||
def save(self, text, page, comment=None, minorEdit=True,
|
def save(self, text, page, comment=None, minorEdit=True,
|
||||||
botflag=True):
|
botflag=True):
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
#
|
#
|
||||||
# countrylist.py
|
# countrylist.py
|
||||||
#
|
#
|
||||||
# Copyright 2015 GOLDERWEB – Jonathan Golder <jonathan@golderweb.de>
|
# Copyright 2017 Jonathan Golder <jonathan@golderweb.de>
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
@@ -34,6 +34,8 @@ from isoweek import Week
|
|||||||
import pywikibot
|
import pywikibot
|
||||||
import mwparserfromhell as mwparser
|
import mwparserfromhell as mwparser
|
||||||
|
|
||||||
|
import jogobot
|
||||||
|
|
||||||
|
|
||||||
class CountryList():
|
class CountryList():
|
||||||
"""
|
"""
|
||||||
@@ -131,6 +133,10 @@ class CountryList():
|
|||||||
# For easy detecting wether we have parsed self
|
# For easy detecting wether we have parsed self
|
||||||
self.parsed = True
|
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 ):
|
def detect_belgian( self ):
|
||||||
"""
|
"""
|
||||||
Detect wether current entry is on of the belgian (Belgien/Wallonien)
|
Detect wether current entry is on of the belgian (Belgien/Wallonien)
|
||||||
@@ -278,6 +284,9 @@ missing!" )
|
|||||||
if self.entry.has( "Titel" ):
|
if self.entry.has( "Titel" ):
|
||||||
self._titel_raw = self.entry.get("Titel").value
|
self._titel_raw = self.entry.get("Titel").value
|
||||||
|
|
||||||
|
# Only use part before possible "<br"
|
||||||
|
self.remove_lines(self._titel_raw)
|
||||||
|
|
||||||
# Remove possible ref-tags
|
# Remove possible ref-tags
|
||||||
for ref in self._titel_raw.ifilter_tags(matches="ref"):
|
for ref in self._titel_raw.ifilter_tags(matches="ref"):
|
||||||
self._titel_raw.remove( ref )
|
self._titel_raw.remove( ref )
|
||||||
@@ -350,6 +359,9 @@ missing!" )
|
|||||||
if self.entry.has( "Interpret" ):
|
if self.entry.has( "Interpret" ):
|
||||||
self._interpret_raw = self.entry.get("Interpret").value
|
self._interpret_raw = self.entry.get("Interpret").value
|
||||||
|
|
||||||
|
# Only use part before possible "<br"
|
||||||
|
self.remove_lines(self._interpret_raw)
|
||||||
|
|
||||||
# Remove possible ref-tags
|
# Remove possible ref-tags
|
||||||
for ref in self._interpret_raw.ifilter_tags(matches="ref"):
|
for ref in self._interpret_raw.ifilter_tags(matches="ref"):
|
||||||
self._interpret_raw.remove( ref )
|
self._interpret_raw.remove( ref )
|
||||||
@@ -452,6 +464,25 @@ missing!" )
|
|||||||
else:
|
else:
|
||||||
return str(keywords[0])
|
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 ):
|
def __str__( self ):
|
||||||
"""
|
"""
|
||||||
Returns str repression for Object
|
Returns str repression for Object
|
||||||
|
|||||||
1
jogobot
1
jogobot
Submodule jogobot deleted from 2173f2984f
8
requirements.txt
Normal file
8
requirements.txt
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
# mwparserfromhell
|
||||||
|
mwparserfromhell
|
||||||
|
|
||||||
|
# isoweek
|
||||||
|
isoweek
|
||||||
|
|
||||||
|
# jogobot
|
||||||
|
git+https://git.golderweb.de/wiki/jogobot.git#egg=jogobot
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
#
|
#
|
||||||
# summarypage.py
|
# summarypage.py
|
||||||
#
|
#
|
||||||
# Copyright 2015 GOLDERWEB – Jonathan Golder <jonathan@golderweb.de>
|
# Copyright 2017 Jonathan Golder <jonathan@golderweb.de>
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or modify
|
# 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
|
# 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 pywikibot
|
||||||
import mwparserfromhell as mwparser
|
import mwparserfromhell as mwparser
|
||||||
|
|
||||||
|
import jogobot
|
||||||
|
|
||||||
from countrylist import CountryList, CountryListError
|
from countrylist import CountryList, CountryListError
|
||||||
|
|
||||||
|
|
||||||
@@ -145,6 +147,9 @@ class SummaryPageEntry():
|
|||||||
|
|
||||||
# If list is from last year, replace year
|
# If list is from last year, replace year
|
||||||
if (current_year - 1) in self.countrylist_wikilink.title:
|
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),
|
self.countrylist_wikilink.title.replace( (current_year - 1),
|
||||||
current_year )
|
current_year )
|
||||||
|
|
||||||
@@ -159,6 +164,10 @@ class SummaryPageEntry():
|
|||||||
|
|
||||||
# If list is from last year, replace year
|
# If list is from last year, replace year
|
||||||
if (current_year ) in self.countrylist_wikilink.title:
|
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,
|
self.countrylist_wikilink.title.replace( current_year,
|
||||||
(current_year - 1) )
|
(current_year - 1) )
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user