Skip to content

Instantly share code, notes, and snippets.

@tabruhn
Last active April 6, 2022 03:28
Show Gist options
  • Save tabruhn/5432317 to your computer and use it in GitHub Desktop.
Save tabruhn/5432317 to your computer and use it in GitHub Desktop.
Simple script to pull full year Eventbrite data for events in Hong Kong. Pulled information is output to a .csv file for convenience. Table fields are "Title" (event title), "Start Date", "Organizer", "Venue", "Address 1", "Address 2", "Event URL". The script asks for input of the users Eventbrite API 'User key' and 'App Key' and returns the eve…
#!/usr/bin/env ruby
require 'net/http'
require 'uri'
require 'json'
require 'csv'
require 'active_support/all'
auth = []
puts "API user key? "
auth[0] = gets.chomp
puts "API app key? "
auth[1] = gets.chomp
auth_parameters =
{
'user_key' => auth[0],
'app_key' => auth[1]
}
count_parameters =
{
'country' => 'HK',
'date' => 'This Year',
'count_only' => 'true'
}
puts auth_parameters
event_search_path = '/json/event_search?'
events_parameters =
{
'country' => 'HK',
'date' => 'This Year',
'max' => '100',
'sort_by' => 'date',
'page' => '1'
}
http = Net::HTTP.new('www.eventbrite.com', 443)
http.use_ssl=true
print "\nGet Count ... \n"
events_params = auth_parameters.merge(count_parameters).collect {|k, v| "#{k}=#{v}"}.join('&')
response = http.request_get( URI.escape( event_search_path + events_params))
#count = JSON.parse( response.body )
print "Total Count of Events: ", count = JSON.parse( response.body )["events"][0]["summary"]["total_items"]
pages = (count/100.0).ceil
arr = Array.new
for i in 1..pages do
print "\nFinding events ... ", "PAGE ", i
events_params2 = auth_parameters.merge(events_parameters).collect {|m, n| "#{m}=#{n}"}.join('&')
response2 = http.request_get( URI.escape( event_search_path + events_params2))
events_list = JSON.parse( response2.body )
puts events_list.size-1
for j in 1..events_list["events"].size-1 do
print "entered"
focusedevent = events_list["events"][j]["event"]
h = Hash.new
h["Title"] = focusedevent["title"]
h["Start Date"] = focusedevent["start_date"]
h["Organizer"] = focusedevent["organizer"]["name"]
h["Venue"] = focusedevent["venue"]["name"]
h["Address 1"] = focusedevent["venue"]["address"]
h["Address 2"] = focusedevent["venue"]["address_2"]
h["Event Url"] = focusedevent["url"]
puts arr.size
arr << h
end
events_parameters['page'] = i+1
end
puts arr
csv_string = CSV.generate do |csv|
csv << arr[0].keys
arr.each do |hash|
csv << hash.values
end
end
open('events.csv', 'w') do |f|
f << csv_string
end
@kaman1
Copy link

kaman1 commented May 26, 2018

hi I want to pull events listing on a CSV file from eventbrite using my app key is this is this script will help me?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment