Created
February 7, 2019 10:35
-
-
Save andrewaguiar/b0222eaac1d1cd5f4186d2934f78a542 to your computer and use it in GitHub Desktop.
Organizes the data import of Flicker
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
# 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