-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelicious_scraper.rb
43 lines (35 loc) · 1.17 KB
/
delicious_scraper.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
require 'rubygems'
require 'csv'
require 'json'
require 'net/http'
def scrape(username, tag)
url = "http://www.delicious.com/v2/json/#{username}/#{tag}?count=1000"
resp = Net::HTTP.get_response(URI.parse(url))
data = resp.body
# we convert the returned JSON data to native Ruby
# data structure - a hash
result = JSON.parse(data, :symbolize_names => true)
#json = JSON.parse(data)
#puts json.first.collect {|k,v| k}.join(',')
#puts json.collect {|node| "#{node.collect{|k,v| v}.join(',')}\n"}.join
CSV.open("#{username}-delicious.csv", "wb") do |csv|
csv << ["URL", "Notes", "Tags", "Description"]
result.each do |r|
csv << ["#{r[:u]}", "#{r[:n]}", "#{r[:t]}", "#{r[:d]}"]
end
end
end
def get_tags(username)
url = "http://feeds.delicious.com/v2/json/tags/#{username}?count=1000"
resp = Net::HTTP.get_response(URI.parse(url))
data = resp.body
# we convert the returned JSON data to native Ruby
# data structure - a hash
result = JSON.parse(data, :symbolize_names => true)
CSV.open("#{username}-delicious-tags.csv", "wb") do |csv|
csv << ["tag", "count"]
result.each do |r|
csv << [r[0].to_s, r[1].to_s]
end
end
end