Skip to content

Instantly share code, notes, and snippets.

@DavidJRobertson
Created October 28, 2012 22:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DavidJRobertson/3970258 to your computer and use it in GitHub Desktop.
Save DavidJRobertson/3970258 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'tumblr_client'
require 'active_record'
GIF_MAX_WIDTH = 1024
GIF_MAX_HEIGHT = 768
Tumblr.configure do |config|
config.consumer_key = "AcHYlG5GaS9xf842H1RC8WF81cvAH9zqf7fvxGSrfHQSy7ksqO"
config.consumer_secret = "SYfZQUh6kGgEG3zAtQwO9jJwGEDcVXBMRg1QUTRIMZqBqDHMUR"
end
$tumblr = Tumblr.new
class IndexedGif
def initializer()
end
attr_accessor :gif_url, :source_url, :source_name, :source_id, :tags, :caption, :individual_caption
def store
@indexed_time = Time.now.getutc
## Make this serialize and store to database
puts self.inspect
end
end
class String
def ends_with?(str)
str = str.to_str
tail = self[-str.length, str.length]
tail == str
end
end
def scour_account(baseurl)
end
def process_post(post)
if(post['source_url'])
# This isn't the original source of this post! Go get it from there.
#TODO: finish this
else
# This is the original source of this post
post['photos'].each do |photo|
image = photo['original_size']
unless image['url'].ends_with?(".gif")
# Not a gif, discard
next
end
if image['width'] > GIF_MAX_WIDTH or image['height'] > GIF_MAX_HEIGHT
# Image too large, discard
next
end
gif = IndexedGif.new
gif.gif_url = image['url']
gif.source_url = post['post_url']
gif.source_name = post['blog_name']
gif.source_id = post['id']
gif.tags = post['tags']
gif.caption = post['caption']
gif.individual_caption = photo['caption']
gif.store
end
end
end
#scour_account "gaysexistheanswer.tumblr.com"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment