diff --git a/euroexange/euroexange.py b/euroexange/euroexange.py index 5528ed1..37a321a 100644 --- a/euroexange/euroexange.py +++ b/euroexange/euroexange.py @@ -25,6 +25,7 @@ import zipfile import shlex import subprocess import email.utils +import hashlib import pywikibot @@ -226,7 +227,11 @@ class EuroExangeBot( pywikibot.bot.BaseBot ): if self.image_update_needed(): self.call_gnuplot( job ) - self.upload_file( job ) + if self.file_changed(): + self.upload_file( job ) + else: + jogobot.output( "No upload needed for Job {}.".format( + self.current_job.image) ) # Nothing to do else: @@ -274,6 +279,26 @@ class EuroExangeBot( pywikibot.bot.BaseBot ): subprocess.call( cmd, cwd=self.wdir, env=plt_env ) + def file_changed( self ): + """ + Checks if generated file and online file differs via sha1 hash + + @returns True if file was changed + @rtype bool + """ + + # Get online file sha1 hash + online_sha1 = self.current_job.filepage.latest_file_info.sha1 + + # Get local file sha1 hash + with open(os.path.join(self.wdir, self.current_job.image),'rb') as fd: + local_sha1 = hashlib.sha1(fd.read()).hexdigest() + + if online_sha1 == local_sha1: + return False + else: + return True + def upload_file( self, job ): """