From ad325a0afef4f2cf6f42c0a1c0bec8669117a53e Mon Sep 17 00:00:00 2001 From: Jonathan Golder Date: Fri, 21 Sep 2018 17:57:39 +0200 Subject: [PATCH] Implement basic gnuplot call --- euroexange/euroexange.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/euroexange/euroexange.py b/euroexange/euroexange.py index 94bd7f2..e8a7bec 100644 --- a/euroexange/euroexange.py +++ b/euroexange/euroexange.py @@ -22,6 +22,8 @@ import urllib.request import shutil import datetime import zipfile +import shlex +import subprocess import pywikibot @@ -36,16 +38,20 @@ class EuroExangeBotJob(): def __init__( self, **kwargs ): self.image = kwargs['image'] + self.script = kwargs['script'] class EuroExangeBot( pywikibot.bot.BaseBot ): working_dir = os.path.dirname(os.path.realpath(__file__)) + "/../wdir" + gnuplot_script_dir = os.path.dirname(os.path.realpath(__file__)) + \ + "/../gnuplot_scripts" + gnuplot = "/usr/bin/gnuplot" data_source = "http://www.ecb.int/stats/eurofxref/eurofxref-hist.zip" zip_file = "eurofxref-hist.zip" csv_file = "eurofxref-hist.csv" - jobs = [ EuroExangeBotJob( image="TEST_Euro_exchange_rate_to_TRY_-_Turkish_Currency_and_Debt_Crisis_2018.svg" ) ] + jobs = [ EuroExangeBotJob( image="TEST_Euro_exchange_rate_to_TRY_-_Turkish_Currency_and_Debt_Crisis_2018.svg", script="Euro_exchange_rate_to_TRY_-_Turkish_Currency_and_Debt_Crisis_2018" ) ] def __init__( self, genFactory, **kwargs ): @@ -194,7 +200,20 @@ class EuroExangeBot( pywikibot.bot.BaseBot ): jogobot.output( "Work on Job {}".format(job.image), "ERROR" ) raise pywikibot.NoPage( filepage ) + self.call_gnuplot( job ) + def call_gnuplot( self, job ): + """ + + @param job: Job to work on + @type job: EuroExangeBotJob + """ + + cmd = shlex.split ( type(self).gnuplot + " " + os.path.realpath( + os.path.join( type(self).gnuplot_script_dir, + job.script + ".plt" ) ) ) + + subprocess.call( cmd, cwd=self.wdir ) def main(*args):