21 Commits

Author SHA1 Message Date
6a6c6ea634 Merge branch 'release-1.3' 2018-10-05 12:27:03 +02:00
7bc4f546f8 Prepare release v1.3 2018-10-05 12:26:38 +02:00
3fb86abac5 Merge branch 'remove-jogobot-submodule' into develop 2018-10-05 11:52:03 +02:00
871cbccc72 Define requirements 2018-10-05 11:50:58 +02:00
e61408f877 Remove jogobot submodule 2018-10-05 11:46:44 +02:00
e6ef20f0a4 Merge branch 'release-1.2' back into develop 2017-11-05 15:53:18 +01:00
f9e4207651 Merge branch 'release-1.2' 2017-11-05 15:52:46 +01:00
5267966fa8 Update version info and copyright notices 2017-11-05 15:52:08 +01:00
0b17998484 Update jogobot-module to v0.1 2017-11-05 15:45:17 +01:00
82662fc882 Merge branch 'release-1.1' 2017-11-05 15:41:45 +01:00
cb11097664 Merge branch 'fs#118-remove-linebreaks' into develop 2017-11-05 15:37:43 +01:00
db6e7fd246 Merge branch 'release-1.0' 2017-11-05 15:36:16 +01:00
af44323930 Cut Titel and Interpret on first linebreak
For some asian countries there is the original name following after a
linebreak. This is not needed in overview, so cat it of.

Related Task: [https://fs.golderweb.de/index.php?do=details&task_id=118 FS#118]
2017-04-10 20:40:39 +02:00
33540344b0 Update jogobot submodule 2016-09-25 18:17:12 +02:00
1958ec222f Add a README.md
To have a basic description of this repo
2016-09-25 16:56:10 +02:00
f2d431ab84 Merge branch 'fs#67-more-detailed-logs' into test-v7 2016-09-25 15:10:27 +02:00
31d06224b0 Update file headers 2016-09-24 21:32:02 +02:00
51d8bb9da9 Read Edit Summary from config
To be able to change the Edit-Summary without touching the source code
2016-09-24 21:29:32 +02:00
f3635b2458 Log year change related actions
Improve logging related to atomatically changed years in list title

[https://fs.golderweb.de/index.php?do=details&task_id=67|FS#67]
2016-08-22 16:45:54 +02:00
962e0cb4de Notice End of Task in Log
Showing end of task in log will help to detect unexpectedly terminated
runs

[https://fs.golderweb.de/index.php?do=details&task_id=67|FS#67]
2016-08-22 16:43:45 +02:00
8948fcc78d Output log each parsed page and revision
To improve quality of log

[https://fs.golderweb.de/index.php?do=details&task_id=67|FS#67]
2016-08-22 15:43:25 +02:00
8 changed files with 117 additions and 13 deletions

3
.gitmodules vendored
View File

@@ -1,3 +0,0 @@
[submodule "jogobot"]
path = jogobot
url = ../jogobot

43
README.md Normal file
View 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>

View File

@@ -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

View File

@@ -11,7 +11,7 @@
#
# 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
# 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):

View File

@@ -3,7 +3,7 @@
#
# 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
# 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

Submodule jogobot deleted from 2173f2984f

8
requirements.txt Normal file
View File

@@ -0,0 +1,8 @@
# mwparserfromhell
mwparserfromhell
# isoweek
isoweek
# jogobot
git+https://git.golderweb.de/wiki/jogobot.git#egg=jogobot

View File

@@ -3,7 +3,7 @@
#
# 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
# 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) )