Skip to content

Instantly share code, notes, and snippets.

@paulcoghlan
Created August 30, 2020 06:35
Show Gist options
  • Save paulcoghlan/10c6c65fa9cf13e32cd9975f6344f36d to your computer and use it in GitHub Desktop.
Save paulcoghlan/10c6c65fa9cf13e32cd9975f6344f36d to your computer and use it in GitHub Desktop.
Create album directories from Flickr album JSON. Copy over JPGs to relevant directories
import json
import shutil
import string
import re
import os
import glob
with open("albums.json", "r") as read_file:
data = json.load(read_file)
albums = data["albums"]
for album in albums:
title = album["title"]
title_stripped = re.sub(r'[^\w\s]','',title)
title_stripped2 = re.sub(r'[\s]','_',title_stripped)
album_dir = "albums/{0}".format(title_stripped2)
if not os.path.isdir(album_dir):
os.makedirs(album_dir)
print title_stripped2
for photo_id in album["photos"]:
print photo_id
with open("photo_{0}.json".format(photo_id), "r") as photo_file:
photo_json = json.load(photo_file)
shutil.copy("photo_{0}.json".format(photo_id), "{0}/".format(album_dir))
listing = glob.glob('*/*_{0}_o.jpg'.format(photo_id))
for filename in listing:
shutil.copy(filename, "{0}/".format(album_dir))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment