Add check for local file existence

This commit is contained in:
Marian Steinbach 2018-04-23 06:35:25 +02:00
parent 0286d30151
commit 8375911b06
1 changed files with 7 additions and 3 deletions

View File

@ -66,9 +66,13 @@ def make_screenshots(url):
]
subprocess.run(command)
blob = bucket.blob('%s/%s' % (subfolder, filename))
with open('./temp/%s/%s' % (subfolder, filename), 'rb') as my_file:
blob.upload_from_file(my_file, content_type="image/png")
blob.make_public()
local_path = './temp/%s/%s' % (subfolder, filename)
if os.path.exists(local_path):
with open(local_path, 'rb') as my_file:
blob.upload_from_file(my_file, content_type="image/png")
blob.make_public()
else:
print("Error: No screenshot created: size=%s, url='%s'" % (size, url))
return filename
if __name__ == "__main__":