From 5b06d2229e74610cdb5fef430e268276d1ca5f6e Mon Sep 17 00:00:00 2001 From: Jonathan Golder Date: Thu, 18 Oct 2018 16:37:11 +0200 Subject: [PATCH] descpage: Implement loading, parsing and updating To be able to change file description page, we need to load current text, do manipulations and to update with new text Issue #1 (https://git.golderweb.de/wiki/jogobot-euroexchange/issues/1) --- euroexchange/config.py | 1 + euroexchange/descpage.py | 73 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 euroexchange/descpage.py diff --git a/euroexchange/config.py b/euroexchange/config.py index ed4a14f..a199c08 100644 --- a/euroexchange/config.py +++ b/euroexchange/config.py @@ -43,3 +43,4 @@ class Config(): zip_file = jogobot.config["euroexchange"]["data_zip_filename"] csv_file = jogobot.config["euroexchange"]["data_csv_filename"] upload_comment = jogobot.config["euroexchange"]["upload_comment"] + gnuplot_script_comment = jogobot.config["euroexchange"]["gnuplot_script_comment"] diff --git a/euroexchange/descpage.py b/euroexchange/descpage.py new file mode 100644 index 0000000..1e6cbb2 --- /dev/null +++ b/euroexchange/descpage.py @@ -0,0 +1,73 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# +# descpage.py +# +# Copyright 2018 Jonathan Golder +# +# 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 +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +# MA 02110-1301, USA. +# +# + +import os + +import pywikibot +import mwparserfromhell as mwparser + +from config import Config + +class DescPageBot(pywikibot.bot.Bot): + """ + Updates file description page with EuroExchangeBot related content + """ + + def treat_job( self, job ): + """ + Handles work on file description page for given job + + @param job Job to work on + @type EuroExchangeBotJob + """ + # Store job + self.job = job + # Store file page object + self.current_page = job.filepage + + # Parse filepage + self.parse_page() + + # Update wiki page + self.update_page() + + def parse_page(self): + """ + Load current page content and parse with mwparser + """ + self.current_page.wikicode = mwparser.parse(self.current_page.text) + + def update_page(self): + """ + Put updated content to wiki + """ + + # Convert wikicode back to str + new_text = str(self.current_page.wikicode) + + # Save new text + self.userPut( self.current_page, + self.current_page.text, + new_text, + summary=Config.gnuplot_script_comment )