Getting multimedia information(modified date)

Hello,

we were trying to update corrupted multimedia files on the local instance. we do have a script to update all the multimedia files. But updating the whole brings the following error;

~/www/echis/releases/2021-11-11_20.35/python_env-3.6/lib/python3.6/site-packages/botocore/client.py in _make_api_call(self, operation_name, api_params)
703 error_code = parsed_response.get("Error", {}).get("Code")
704 error_class = self.exceptions.from_code(error_code)
--> 705 raise error_class(parsed_response, operation_name)
706 else:
707 return parsed_response
ClientError: An error occurred (SlowDown) when calling the PutObject operation (reached max retries: 4): Resource requested is unreadable, please reduce your request rate

Since the updates are too much for the server, we should omit recently updated files. So that the above performance-related error won't happen again.

As a solution, we were modifying the script to update the multimedia files. But unable to get the modified date of multimedia files.

In [85]: import os
...: import time
...: #import datetime
...: from datetime import datetime
...: for missing_file, image_id in missing_multimedia.items():
...: image = CommCareImage.get(image_id)
...: filename = options["base_path"] + missing_file
...: with open(filename, "rb") as f:
...: image_data = f.read()
...: modification_time=os.path.getmtime(image.last_modified)
...: local_time = time.ctime(modification_time)
...: filedate=datetime.strptime(local_time, "%a %b %d %H:%M:%S %Y")
...: print(filedate)
...: d2=datetime(2021,11,11,18,00)
...: if(filedate > d2):
...: print("Already modified file")
...: else:
image.put_attachment(
...: image_data,
...: image.attachment_id,
...: content_type=image.get_mime_type(image_data, filename=missing_file),
...: domain=SHARED_DOMAIN,
...: )
...: print(f"Successfully updated image {missing_file}")

modification_time=os.path.getmtime(image.last_modified) this brings an error.

When we try to print the image data using the following code:

for path, media_map in app.multimedia_map.items():
...: image = CommCareImage.get(media_map.multimedia_id)
...: try:
...: print(image)
...: except ResourceNotFound as e:
...: print(e)

The output is something like this:

CommCareImage(_attachments=None, _id='9406dada590522cbd883e2cdd1df2231', _rev='6-8e29337cd4bfb27176db830a1e6b92f6', aux_media=[AuxMedia(attachment_id='7182afcfe64db13d19b8f348d2c1c64a-4301x1196.PNG', checksum='7182afcfe64db13d19b8f348d2c1c64a', doc_type='AuxMedia', media_meta={'size': {'width': 4301, 'height': 1196}}, notes=None,
uploaded_by=None, uploaded_date=datetime.datetime(2019, 1, 14, 10, 8, 47, 503854), uploaded_filename='hq_logo_android_login.png')], doc_type='CommCareImage', external_blobs={'7182afcfe64db13d19b8f348d2c1c64a-4301x1196.PNG': BlobMetaRef(blobmeta_id=2456094, content_length=190021, content_type='image/png', doc_type='BlobMetaRef', key='c3b9663de7534f709f9b898bb6dc82a3')}, file_hash='7182afcfe64db13d19b8f348d2c1c64a', last_modified=datetime.datetime(2019, 1, 14, 10, 8, 47, 377947), licenses=[], owners=['fmoh-echis'], shared_by=[], tags={}, valid_domains=['fmoh-echis'])

The above output is for a single multimedia file. We should be able to extract either uploaded_date or modified_date.

As descried on the above code:
modification_time=os.path.getmtime(image.last_modified)
brings an error.