Skip to content

Instantly share code, notes, and snippets.

@andrewaguiar
Created February 7, 2019 10:35
Show Gist options
  • Save andrewaguiar/b0222eaac1d1cd5f4186d2934f78a542 to your computer and use it in GitHub Desktop.
Save andrewaguiar/b0222eaac1d1cd5f4186d2934f78a542 to your computer and use it in GitHub Desktop.
Organizes the data import of Flicker
# Organizes the data import of Flicker
# 1 - Download all files
# 2 - Unzip them in a folder
# 3 - Run this script inside the folder
# 4 - Bingo, photos will be placed inside build/ organized by albums
require 'json'
require 'fileutils'
albums = JSON.parse(File.read('./albums.json'))['albums']
all_photo_files = Dir['*.*']
puts "Organizing #{all_photo_files.size} photos in #{albums.size} albums"
albums.each do |album|
title = album['title'].gsub("/", '')
puts ":: #{title}"
FileUtils.mkdir_p("build/#{title}")
album['photos'].reject { |photo_id| photo_id == '0' }.each do |photo_id|
begin
photo = JSON.parse(File.read("./photo_#{photo_id}.json"))
extention = photo['original'].split('.')[-1]
photo_file = all_photo_files.find { |p| p.end_with?("_#{photo['id']}_o.#{extention}") }
if photo_file
puts "#{photo['id']} -> #{photo_file}"
FileUtils.mv(photo_file, "build/#{title}/")
end
rescue => err
puts "ERROR: #{photo_id} - #{err}"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment