Flying memes

I’ve just checked in at WC2010 Johannesburg Stadium from home

Thanks to Uncle Pear suggestion I realized that you can easily check-in in every Foursquare venue simply invoking its id using the API, to try this behavior I checked in at Johannesburg  WC2010 stadium from my home in Italy.

Here’s the simple snippet of code you can use (from a linux shell):

curl -u sandro.paganotti@gmail.com:my_password -d "vid=4762107" http://api.foursquare.com/v1/checkin

Foursquare api are really easy to use and lets you invoke up to 200 times each method each hour, so a quite simple exercise can be write a simple program that automatically check-in a selected account in a given array of locations:


require 'rubygems'
require 'restclient'
require 'nokogiri'

counter = -1
debug   = true

travel = [
            # minutes to wait, venue to check-in
            [5 ,4762107],
            [10,2335319]
         ]

RestClient.add_before_execution_proc do |req, params|
    req.basic_auth 'sandro.paganotti@gmail.com', 'my_password'
end

loop do
    time, venue_id = travel[counter = ((counter + 1) % travel.size)]
    puts "sleeping #{time} minutes.." if debug
    sleep time * 60
    response = RestClient.post "http://api.foursquare.com/v1/checkin", :vid=>venue_id
    puts  ['checkin','message'].inject(Nokogiri::XML(response.body)) { |s,r| s.send(:at, r) }.inner_text
end

By invoking this code an infinite loop will check-in the provided account into each of the given venues waiting a configurable amount of time between each of them.

Here’s the result:

sandropaganotti$ ruby venue.rb
sleeping 5 minutes..
OK! We've got you @ WC2010 Soccer City Stadium. This is your 2nd checkin here!
sleeping 10 minutes..
OK! We've got you @ Service Station Cafe. This is your 1st checkin here!
sleeping 5 minutes..

Tags: