Last active
August 29, 2015 14:02
-
-
Save tsaiid/e49e633916f48e25fc6e to your computer and use it in GitHub Desktop.
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 'json' | |
require 'open-uri' | |
require 'image_size' | |
CONSUMER_KEY = 'YOUR_KEY' | |
PHOTOS_PER_PAGE = 20 | |
BASE_URL = 'https://api.500px.com' | |
POPULAR_URL = BASE_URL + '/v1/photos?' + | |
'consumer_key=' + CONSUMER_KEY + '&' + | |
'feature=popular' + '&' + | |
'image_size=4' + '&' + | |
'sort=created_at' + '&' + | |
'rpp=' + PHOTOS_PER_PAGE.to_s | |
# remove current images | |
WORKING_DIR = Dir.pwd | |
## flickr photos contain '_' | |
Dir["*.jpg"].select {|x| x =~ /^[^_]+$/}.each do |f| | |
File.unlink(f) | |
end | |
# read RSS and fetch images | |
JSON.load(open(POPULAR_URL))['photos'].each do |photo| | |
image_url = photo['image_url'].gsub(/4\.jpg/, '2048.jpg') | |
filename = photo['image_url'].match(/\/([^\/]+)\/4\.jpg/)[1] + '.jpg' | |
# fetch image and write | |
image = open(image_url).read | |
max_size = ImageSize.new(image).size.max | |
if (max_size >= 1920) | |
File.open(filename, 'w') do |fo| | |
fo.write image | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment