Guest User

Untitled

a guest
Feb 13th, 2014
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.92 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2. require 'nokogiri'
  3. require 'open-uri'
  4. require 'sequel'
  5. require 'sqlite3'
  6. require 'pry'
  7. require 'uri'
  8. require 'cgi'
  9.  
  10.  
  11.  
  12. clubland = "http://www.clublandlv.com/forum.php"
  13.  
  14.   doc = Nokogiri::HTML(open(clubland))
  15.    
  16.   doc.css("#c_cat10").each do |grab|
  17.     genres = grab.css(".forumtitle").map(&:text)
  18.     genre_links = grab.css(".forumtitle"){[:href]}
  19.    
  20.     genre_links = genre_links.map do |link|
  21.     link_id = link.children.first["href"]
  22.     CGI.parse(URI.parse(link_id).query)['f'].first.to_i
  23.   end
  24.  
  25.  
  26.   DB = Sequel.connect('sqlite:///Users/RyanOConnor/workspace/testing/clublandlv.sqlite')
  27.     # If i pass the argument to be .dinstinct matching the :genre table, i recieve a
  28.     # DISTINCT ON not supported error. If i remove the argument, duplicates are inserted.
  29.     genre_db = DB[:genres].distinct(:genre)
  30.       genre_db.import([:genre, :forum_id], genres.zip(genre_links))
  31.  
  32.  
  33. end
Advertisement
Add Comment
Please, Sign In to add comment