Skip to content

Instantly share code, notes, and snippets.

@ryanj
Created August 2, 2011 18:21
Show Gist options
  • Save ryanj/1120829 to your computer and use it in GitHub Desktop.
Save ryanj/1120829 to your computer and use it in GitHub Desktop.
Scan public events from the Eventbrite API, copy them into a couchbase instance
// This script should allow you to
// load Eventbrite's public event data
// into a couchbase data store.
// First, install the Eventbrite client library:
// npm install eventbrite
// Load the library - https://github.com/ryanjarvinen/eventbrite.npm
var Eventbrite = require('eventbrite');
// Load creationix's couch-client
var CouchClient = require('couch-client');
// Initialize the Eventbrite API client - http://www.eventbrite.com/api/key/
var eb_client = Eventbrite('YOUR_API_KEY');
// Initialize your couchbase client:
var db = CouchClient('http://localhost:5984/eventbrite_public/');
// some local counters:
var total_events = 0;
var pub_events = 0;
var online_events = 0;
var pages = 0;
// 100 per page is Eventbrite's max
var max_per_page = 100;
// First, find the total number of "pages" or requests
// that will be needed in order to pull this data
eb_client.event_search( {'count_only' : true}, function(err, data){
console.log(data.events[0].summary);
total_events = data.events[0].summary.total_items;
pages = total_events / max_per_page;
console.log( pages );
// Loop over each page, loading the data into couchbase
for (var i = 1; i <= pages; i+=1){
eb_client.event_search({'max' : max_per_page, 'page': i }, function(err, data){
console.log(data.events[0].summary);
for(var j=1; j <= max_per_page; j+=1){
if(data.events[j]['event']){
var e = data.events[j]['event'];
if(e.venue && e.venue.latitude && e.venue.longitude){
//pub_events.push(data.events[j]['event']);
pub_events += 1;
console.log( "pub Events length: " + pub_events );
console.log( "processing: " + e.id + ", titled: '" + e.title + "', at long:" + e.venue.longitude + ", lat: "+e.venue.latitude);
db.save({_id: e.id.toString(), 'eb_event': e, 'loc': [ e.venue.longitude, e.venue.latitude ], "geometry": {"type":"Point","coordinates": [ e.venue.longitude, e.venue.latitude ]}}, function(err, result) {
if (err) throw err;
//console.log(result);
});
}
else{
online_events += 1;
console.log( "skipping: " + e.id + ", titled: '" + e.title + "', due to lack of location info");
console.log( "online Events length: " + online_events );
}
}
}
});
console.log("found " + pub_events + " events so far, on page " + i + " of " + pages );
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment