Load jobs from json file
This commit is contained in:
@@ -26,6 +26,7 @@ import shlex
|
|||||||
import subprocess
|
import subprocess
|
||||||
import email.utils
|
import email.utils
|
||||||
import hashlib
|
import hashlib
|
||||||
|
import json
|
||||||
|
|
||||||
import pywikibot
|
import pywikibot
|
||||||
|
|
||||||
@@ -46,6 +47,7 @@ class EuroExangeBotJob():
|
|||||||
|
|
||||||
class EuroExangeBot( pywikibot.bot.BaseBot ):
|
class EuroExangeBot( pywikibot.bot.BaseBot ):
|
||||||
|
|
||||||
|
base_dir = os.path.dirname(os.path.realpath(__file__)) + "/.."
|
||||||
working_dir = os.path.dirname(os.path.realpath(__file__)) + "/../wdir"
|
working_dir = os.path.dirname(os.path.realpath(__file__)) + "/../wdir"
|
||||||
gnuplot_script_dir = os.path.dirname(os.path.realpath(__file__)) + \
|
gnuplot_script_dir = os.path.dirname(os.path.realpath(__file__)) + \
|
||||||
"/../gnuplot_scripts"
|
"/../gnuplot_scripts"
|
||||||
@@ -55,10 +57,6 @@ class EuroExangeBot( pywikibot.bot.BaseBot ):
|
|||||||
csv_file = "eurofxref-hist.csv"
|
csv_file = "eurofxref-hist.csv"
|
||||||
upload_comment = "Bot: ([[User:Jogobot/Euroexange|euroexange]]) update chart"
|
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 ):
|
def __init__( self, genFactory, **kwargs ):
|
||||||
|
|
||||||
# Init working directory
|
# Init working directory
|
||||||
@@ -71,10 +69,10 @@ class EuroExangeBot( pywikibot.bot.BaseBot ):
|
|||||||
# Make sure input data is uptodate
|
# Make sure input data is uptodate
|
||||||
self.update_data()
|
self.update_data()
|
||||||
|
|
||||||
for job in type(self).jobs:
|
# Load and treat jobs
|
||||||
|
for job in self.load_jobs():
|
||||||
self.treat_job(job)
|
self.treat_job(job)
|
||||||
|
|
||||||
pass
|
|
||||||
|
|
||||||
def init_wdir(self):
|
def init_wdir(self):
|
||||||
"""
|
"""
|
||||||
@@ -199,6 +197,23 @@ class EuroExangeBot( pywikibot.bot.BaseBot ):
|
|||||||
os.path.join(self.wdir, type(self).csv_file)),
|
os.path.join(self.wdir, type(self).csv_file)),
|
||||||
path=self.wdir )
|
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 ):
|
def treat_job( self, job ):
|
||||||
"""
|
"""
|
||||||
Handles working on specific jobs
|
Handles working on specific jobs
|
||||||
|
|||||||
Reference in New Issue
Block a user