Skip to content

Instantly share code, notes, and snippets.

@n-shinya
Created March 18, 2012 14:47
Show Gist options
  • Save n-shinya/2074495 to your computer and use it in GitHub Desktop.
Save n-shinya/2074495 to your computer and use it in GitHub Desktop.
ATND Search API
require 'pp'
require 'net/http'
require 'json'
require 'sqlite3'
db = SQLite3::Database.new("data.db")
url = {
:scheme => 'http',
:server => 'api.atnd.org',
:port => '80',
:path => '/events',
:query => 'keyword=Heroku&format=json'
}
Net::HTTP.start(url[:server],url[:port]) do |http|
response = http.get(url[:path] + '?' + url[:query]);
json = JSON.parse(response.body)
json["events"].each do |event|
title = event["title"]
event_url = event["event_url"]
puts title
puts event_url
db.execute("select count(*) from event where url = ?", event_url) do |row|
if row[0].to_i < 1
db.execute("insert into event values(?,?)", title, event_url)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment