Add update frequenzy in days to job
Check against timestamp of latest file revision
This commit is contained in:
@@ -40,6 +40,7 @@ class EuroExangeBotJob():
|
|||||||
|
|
||||||
self.image = kwargs['image']
|
self.image = kwargs['image']
|
||||||
self.script = kwargs['script']
|
self.script = kwargs['script']
|
||||||
|
self.freq = kwargs['freq']
|
||||||
|
|
||||||
|
|
||||||
class EuroExangeBot( pywikibot.bot.BaseBot ):
|
class EuroExangeBot( pywikibot.bot.BaseBot ):
|
||||||
@@ -53,7 +54,9 @@ 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" ) ]
|
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 ):
|
||||||
|
|
||||||
@@ -219,10 +222,41 @@ class EuroExangeBot( pywikibot.bot.BaseBot ):
|
|||||||
"ERROR" )
|
"ERROR" )
|
||||||
raise pywikibot.NoPage( filepage )
|
raise pywikibot.NoPage( filepage )
|
||||||
|
|
||||||
|
# Check if update is necessary
|
||||||
|
if self.image_update_needed():
|
||||||
self.call_gnuplot( job )
|
self.call_gnuplot( job )
|
||||||
|
|
||||||
self.upload_file( job )
|
self.upload_file( job )
|
||||||
|
|
||||||
|
# Nothing to do
|
||||||
|
else:
|
||||||
|
jogobot.output( "No update needed for Job {}".format(
|
||||||
|
self.current_job.image) )
|
||||||
|
|
||||||
|
def image_update_needed( self ):
|
||||||
|
"""
|
||||||
|
Checks weather image update intervall is reached.
|
||||||
|
|
||||||
|
@returns True if update needed
|
||||||
|
@rtype bool
|
||||||
|
"""
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
# Get datetime of last update
|
||||||
|
last_update = self.current_job.filepage.latest_file_info.timestamp
|
||||||
|
|
||||||
|
# Get current time
|
||||||
|
now = pywikibot.Site().getcurrenttime()
|
||||||
|
|
||||||
|
# Calculate allowed delta (with tolerance)
|
||||||
|
delta = datetime.timedelta( days=self.current_job.freq, hours=-2 )
|
||||||
|
|
||||||
|
if now >= last_update + delta:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
def call_gnuplot( self, job ):
|
def call_gnuplot( self, job ):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user