SHARE
TWEET

Titelindex aus JSON-Dateien eines Flickr-Downloads machen

goebelmasse Nov 24th, 2018 29 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python3
  2. ########################################################################
  3. #
  4. # index.py
  5. # Indexdatei aus den JSON-Dateien von Flickr erstellen
  6. #
  7. ########################################################################
  8.  
  9. import glob
  10. import json
  11. import re
  12.  
  13. re_tonumber = re.compile(r'\D*(\d+)\D*')
  14. re_filename = re.compile(r'JSON/(.+)\.json')
  15.  
  16. s_format = '{0:<18} : {1}\n'
  17.  
  18.  
  19. def tonumber(rawname):
  20.     mo = re_tonumber.search(rawname)
  21.     return int(mo.group(1))
  22.  
  23. def tofilename(rawname):
  24.     mo = re_filename.match(rawname)
  25.     return mo.group(1)
  26.  
  27. with open("index.txt", "wt") as outp:
  28.     outp.write(s_format.format("DATEINAME", "TITEL"))
  29.     for fpath in sorted(glob.glob('JSON/*.json'), key=tonumber):
  30.         fname = tofilename(fpath)
  31.         with open(fpath, "rt") as jf:
  32.             forget = jf.read(1) # BOM überspringen
  33.             jdict = json.load(jf)
  34.             outp.write(s_format.format(fname, jdict['Title']))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top