-
Notifications
You must be signed in to change notification settings - Fork 13
/
flickriser.rb
executable file
·46 lines (33 loc) · 1.04 KB
/
flickriser.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env ruby
# This is heavy cruft but I cannot use a Flickr plugin on gh-pages, and anyway
# what about my API secret?
require 'flickraw'
require 'dotenv'
require 'yaml'
Dotenv.load
FlickRaw.api_key = ENV['FLICKR_API_KEY']
FlickRaw.shared_secret = ENV['FLICKR_SECRET']
licenses = flickr.photos.licenses.getInfo
yaml = File.open '_data/intermediate_pictures.yml', 'w'
l = []
f = flickr.photosets.getPhotos(photoset_id: ENV['FLICKR_ALBUM_ID'])
f['photo'].each do |p|
h = {}
data = flickr.photos.getInfo(photo_id: p['id'])
h['photo_page'] = data['urls'][0]['_content']
h['title'] = data['title']
h['photo_url'] = FlickRaw.url_m(p)
license = licenses.select {|l| l['id'] == data['license']}[0]
h['license'] = license['name'].split(' License')[0]
h['license_url'] = license['url']
h['photographer'] = 'jane'
h['title'] = 'Islington Academy session'
data['tags'].each do |tag|
if tag['raw'].match('photographer')
h['photographer'] = tag['raw'].split(':')[1]
end
end
l << h
end
yaml.write l.to_yaml
yaml.close