Skip to content

Instantly share code, notes, and snippets.

@o-sam-o
Created February 23, 2016 04:17
Show Gist options
  • Save o-sam-o/78eae7adea73512e1273 to your computer and use it in GitHub Desktop.
Save o-sam-o/78eae7adea73512e1273 to your computer and use it in GitHub Desktop.
untappd_scrape_checkins.rb
require 'awesome_print'
require 'base58'
require 'net/http'
require 'uri'
require 'untappd'
require File.dirname(__FILE__) + '/secrets'
Untappd.configure do |config|
config.client_id = UNTAPPD_CLIENT_ID
config.client_secret = UNTAPPD_SECRET
config.redirect_url = 'http://example.com'
config.gmt_offset = -8
end
ALREADY_POSTED_FILE = File.dirname(__FILE__) + "/already_posted.txt"
p "Beers for #{UNTAPPD_USERNAME}"
max_id = nil
p "Writing results to #{ALREADY_POSTED_FILE}"
File.open(ALREADY_POSTED_FILE, 'w') do |file|
loop do
feed = Untappd::User.feed(UNTAPPD_USERNAME, {max_id: max_id, limit: 50})
raise "request error. API limit exceeded? : #{feed.to_json}" if feed.pagination.nil?
p "Fetched page"
feed.checkins.items.each do |checkin|
if checkin.checkin_comment =~ /https:\/\/flic.kr\/p\/(\w+)/
encoded_flickr_id = $1
flickr_id = Base58.decode(encoded_flickr_id)
p "Found Flickr checkin with id #{flickr_id}"
file << "#{flickr_id}\n"
end
end
max_id = feed.pagination.max_id
break if max_id.nil? || max_id == ''
p "max_id: #{max_id}"
end
end
p "Done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment