Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- ########################################################################
- #
- # index.py
- # Indexdatei aus den JSON-Dateien von Flickr erstellen
- #
- ########################################################################
- import glob
- import json
- import re
- re_tonumber = re.compile(r'\D*(\d+)\D*')
- re_filename = re.compile(r'JSON/(.+)\.json')
- s_format = '{0:<18} : {1}\n'
- def tonumber(rawname):
- mo = re_tonumber.search(rawname)
- return int(mo.group(1))
- def tofilename(rawname):
- mo = re_filename.match(rawname)
- return mo.group(1)
- with open("index.txt", "wt") as outp:
- outp.write(s_format.format("DATEINAME", "TITEL"))
- for fpath in sorted(glob.glob('JSON/*.json'), key=tonumber):
- fname = tofilename(fpath)
- with open(fpath, "rt") as jf:
- forget = jf.read(1) # BOM überspringen
- jdict = json.load(jf)
- outp.write(s_format.format(fname, jdict['Title']))
Add Comment
Please, Sign In to add comment