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 (#1)
This commit is contained in:
@@ -43,3 +43,4 @@ class Config():
|
|||||||
zip_file = jogobot.config["euroexchange"]["data_zip_filename"]
|
zip_file = jogobot.config["euroexchange"]["data_zip_filename"]
|
||||||
csv_file = jogobot.config["euroexchange"]["data_csv_filename"]
|
csv_file = jogobot.config["euroexchange"]["data_csv_filename"]
|
||||||
upload_comment = jogobot.config["euroexchange"]["upload_comment"]
|
upload_comment = jogobot.config["euroexchange"]["upload_comment"]
|
||||||
|
gnuplot_script_comment = jogobot.config["euroexchange"]["gnuplot_script_comment"]
|
||||||
|
|||||||
73
euroexchange/descpage.py
Normal file
73
euroexchange/descpage.py
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
#
|
||||||
|
# descpage.py
|
||||||
|
#
|
||||||
|
# Copyright 2018 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
|
||||||
|
# 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 )
|
||||||
Reference in New Issue
Block a user