0

I have 5000 Zip archives that contains a json file with an information (versionName),

I want to rename those zip files, the best way I found to do that in python is to read the jsons and get the information I need, then rename each zip like that : "Archive_name.zip => Archive_name_versionName.zip"

Here is my python code :

import zipfile
archive = zipfile.ZipFile('/home/AndroidBags/aasuited.net.word.zip', 'r')
print(archive)
jsonre = archive.read('meta_google_play/apk_aasuited.net.word.json')
print(jsonre)

Here the result of that script :

{"appdata": [{"versionName": "1.24.1", "size": 19480447}]}

How can I acces the versionName value and rename the zip file in python ? Thank you

userHG
  • 567
  • 4
  • 29

1 Answers1

0
import os
import json

version_name = json.loads(jsonre)['appdata'][0]['versionName']
os.rename(
    '/home/AndroidBags/aasuited.net.word.zip',
    './aasuited.net.word.' + version_name + '.zip'
)

This also moves the zip file to the current work directory.

mossymountain
  • 175
  • 1
  • 7