Created
December 15, 2018 16:35
-
-
Save pmow/4bbd74df02315913429378ffb5cb4a96 to your computer and use it in GitHub Desktop.
flickr_flatten
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import fnmatch | |
import json | |
from functions import * | |
verbose = 0 | |
jsonpath= '/mnt/media2/Flickr.Dump/json/' | |
mediapath= '/mnt/media2/Flickr.Dump/media/' | |
outputpath= '/mnt/media2/Flickr.Dump/output/' | |
for root, dirs, files in os.walk(jsonpath): | |
for filename in fnmatch.filter(files,'photo_*.json'): | |
if verbose: print('Reading '+ os.path.join(root, filename)) | |
fullfilenamepath = os.path.join(root, filename) | |
j_obj = json.load(open(fullfilenamepath,'r')) | |
if len(j_obj['albums']) == 0: | |
print "Id: ", j_obj['id'], 'is without album' | |
copyphoto(j_obj['id'],mediapath,outputpath,'noAlbum') | |
elif len(j_obj['albums']) == 1: | |
print "Id: ", j_obj['id'], ' goes in album ', j_obj['albums'][0]['title'] | |
copyphoto(j_obj['id'],mediapath,outputpath,j_obj['albums'][0]['title']) | |
elif len(j_obj['albums']) == 2: | |
print "Id: ", j_obj['id'], ' goes in album ', j_obj['albums'][0]['title'] | |
print "Id: ", j_obj['id'], ' goes in album ', j_obj['albums'][1]['title'] | |
copyphoto(j_obj['id'],mediapath,outputpath,j_obj['albums'][0]['title']) | |
copyphoto(j_obj['id'],mediapath,outputpath,j_obj['albums'][1]['title']) | |
else: | |
print "Id: ", j_obj['id'], ' has ', len(j_obj['albums']),' albums! Error!' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import fnmatch | |
from shutil import copyfile | |
def copyphoto(flickrid,frompath,topath,album,negated = 0): | |
print "flickrid is "+flickrid,' frompath is '+frompath,' topath is '+topath,' album is '+album | |
if not os.path.exists(topath+'/'+album): | |
os.makedirs(topath+'/'+album) | |
for root, dirs, files in os.walk(frompath): | |
for filename in fnmatch.filter(files,'*_'+flickrid+'_o.*'): | |
print "Copying "+filename+" to "+topath | |
if negated == 0: | |
copyfile(os.path.join(root,filename),topath+'/'+album+'/'+filename) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Will take dir full of JSON and MEDIA, and arrange media in folders according to the JSON albums.
This is the Flickr format when you hit the "download all" button.