Skip to content
This repository has been archived by the owner on Jul 2, 2021. It is now read-only.

Commit

Permalink
Added script to reverse list of images in a gallery
Browse files Browse the repository at this point in the history
  • Loading branch information
tmuguet committed Sep 9, 2017
1 parent 239e51e commit d2a1c58
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions reverse.py
@@ -0,0 +1,27 @@
#!/usr/bin/python

import argparse
import json
import os
import shutil
import xml.etree.ElementTree as ET

parser = argparse.ArgumentParser(description='Reverses the list of images')
parser.add_argument('source', metavar='source', help='gallery')

args = parser.parse_args()

if not os.path.isdir(args.source) or not os.path.isfile(os.path.join(args.source, 'info.json')):
print "Error: can't find source '%s'" % (args.source)
exit(1)

print "Inversing list..."
with open(os.path.join(args.source, 'info.json'), 'r') as destination_data:
destination = json.load(destination_data)

destination['list'].pop(0)
destination['list'] = destination['list'][::-1]
destination['list'].insert(0, {})

with open(os.path.join(args.source, 'info.json'), 'w') as destination_data:
destination_data.write(json.dumps(destination, sort_keys=True, indent=4, separators=(',', ': ')))

0 comments on commit d2a1c58

Please sign in to comment.