Browse Source

Load jobs from json file

develop
Jonathan Golder 6 years ago
parent
commit
46447d6f32
  1. 27
      euroexange/euroexange.py

27
euroexange/euroexange.py

@ -26,6 +26,7 @@ import shlex
import subprocess
import email.utils
import hashlib
import json
import pywikibot
@ -46,6 +47,7 @@ class EuroExangeBotJob():
class EuroExangeBot( pywikibot.bot.BaseBot ):
base_dir = os.path.dirname(os.path.realpath(__file__)) + "/.."
working_dir = os.path.dirname(os.path.realpath(__file__)) + "/../wdir"
gnuplot_script_dir = os.path.dirname(os.path.realpath(__file__)) + \
"/../gnuplot_scripts"
@ -55,10 +57,6 @@ class EuroExangeBot( pywikibot.bot.BaseBot ):
csv_file = "eurofxref-hist.csv"
upload_comment = "Bot: ([[User:Jogobot/Euroexange|euroexange]]) update chart"
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", freq=1 )
]
def __init__( self, genFactory, **kwargs ):
# Init working directory
@ -71,10 +69,10 @@ class EuroExangeBot( pywikibot.bot.BaseBot ):
# Make sure input data is uptodate
self.update_data()
for job in type(self).jobs:
# Load and treat jobs
for job in self.load_jobs():
self.treat_job(job)
pass
def init_wdir(self):
"""
@ -199,6 +197,23 @@ class EuroExangeBot( pywikibot.bot.BaseBot ):
os.path.join(self.wdir, type(self).csv_file)),
path=self.wdir )
def load_jobs( self ):
"""
Load jobs from json file
@returns Generator of EuroExangeBotJob objects
@rtype generator
"""
# Load json jobs file
with open( os.path.join(self.base_dir, "jobs.json"), "r") as fd:
jobs_js = json.load( fd )
# yield each job
for job_args in jobs_js:
yield EuroExangeBotJob( **job_args )
def treat_job( self, job ):
"""
Handles working on specific jobs

Loading…
Cancel
Save