Created
August 27, 2023 03:29
-
-
Save jordancrawfordnz/b5fd8f1233f6705275ce24d3411f319b to your computer and use it in GitHub Desktop.
Generate summary CSV for Flickr export
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
require 'csv' | |
ALBUMS_PATH = "[enter path here]/albums.json" # The path of the `albums.json` file | |
PHOTO_FOLDER_PATH = "[enter path here]" # The path where all the photo JSON files are | |
EXPORT_PATH = "[enter path here]/metadata_summary.csv" # The path to save the CSV export | |
FlickrAlbum = Struct.new(:id, :title, :description, :photos) | |
FlickrData = Struct.new(:id, :name, :description, :date_taken, :date_imported, :geo, :comments, :album) | |
# Parse photos data | |
all_photo_data = Dir.entries(PHOTO_FOLDER_PATH).map do |entry| | |
next if entry == "." || entry == ".." | |
json = JSON.parse(File.read(PHOTO_FOLDER_PATH + entry)) | |
photo_data = FlickrData.new( | |
json["id"], | |
json["name"], | |
json["description"].presence, | |
json["date_taken"], | |
json["date_imported"], | |
json["geo"], | |
json["comments"], | |
nil | |
) | |
photo_data | |
end.compact.index_by(&:id); nil | |
# Parse albums data | |
album_json = JSON.parse(File.read(ALBUMS_PATH)) | |
all_albums_data = album_json["albums"].map do |json_album| | |
album_data = FlickrAlbum.new( | |
json_album["id"], | |
json_album["title"], | |
json_album["description"] | |
) | |
photos = all_photo_data.slice(*json_album["photos"]) | |
photos.each { |(key, photo)| photo.album = album_data } | |
album_data.photos = photos | |
album_data | |
end | |
# Export to CSV | |
CSV.open(EXPORT_PATH,'w', | |
:write_headers => true, | |
:headers => [ | |
"id", | |
"name", | |
"description", | |
"date_taken", | |
"date_imported", | |
"geo", | |
"comments", | |
"album_id", | |
"album_title", | |
"album_description" | |
] | |
) do |csv| | |
all_photo_data.values.each do |data| | |
csv << [ | |
data.id, | |
data.name, | |
data.description, | |
data.date_taken, | |
data.date_imported, | |
data.geo, | |
data.comments, | |
data.album&.id, | |
data.album&.title, | |
data.album&.description | |
] | |
end | |
end; nil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When exporting data from Flickr (via the "Your Flickr Data" export), you get a significant amount of JSON files (one for each photo) and some album information.
I wanted to extract this information to move it to another system.
This Ruby code parses the album and photo files and produces a CSV summary. Then you can apply CSV filtering in a tool like Excel to further narrow down your data.