Skip to content

Instantly share code, notes, and snippets.

@eduardoleon
Created May 3, 2020 05:12
Show Gist options
  • Save eduardoleon/9b0c836b17ae34361647c733650b3276 to your computer and use it in GitHub Desktop.
Save eduardoleon/9b0c836b17ae34361647c733650b3276 to your computer and use it in GitHub Desktop.
This is crude, but it will do for now.
#!/usr/bin/python
import os
import subprocess
import sys
def extract_media(path):
args = ['unzip', path, '*media*']
subprocess.run(args)
def list_media(path):
args = ['unzip', '-l', path, '*media*']
print(subprocess.run(args).stdout)
def move_media(app):
media = f'{app}/media'
for entry in os.scandir(media):
os.rename(entry.path, entry.name.replace('image', 'solución-').replace('jpeg', 'jpg'))
os.rmdir(media)
os.rmdir(app)
def file_type(path):
with open(path) as file:
for line in file:
args = ['file', line.rstrip()]
print(subprocess.run(args).stdout)
assoc = dict()
assoc['-e'] = extract_media
assoc['-l'] = list_media
assoc['-m'] = move_media
assoc['-t'] = file_type
if __name__ == '__main__':
func = assoc[sys.argv[1]]
func(sys.argv[2])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment