Guest User

Untitled

a guest
Feb 13th, 2014
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.69 KB | None | 0 0
  1. # Here is a picture of all the tables that are created through the 3 scripts: http://snag.gy/cySx0.jpg
  2.  
  3. require 'nokogiri'[]
  4.  
  5. #This script will go to the link below, and extract all of the Genre names and Genre IDs.
  6. #The output will be in the form of two arrays, one for names and one for links.
  7.  
  8. clubland = "http://www.clublandlv.com/forum.php"
  9.  
  10.   doc = Nokogiri::HTML(open(clubland))
  11.    
  12.   doc.css("#c_cat10").each do |grab|
  13.     genres = grab.css(".forumtitle").map(&:text)
  14.     genre_links = grab.css(".forumtitle"){[:href]}
  15.    
  16.     genre_links = genre_links.map do |link|
  17.     link_id = link.children.first["href"]
  18.       CGI.parse(URI.parse(link_id).query)['f'].first.to_i
  19.   end
  20.  
  21. #This part of the script will import the results to the database, in the specified columns.
  22.  
  23.   DB = Sequel.connect('sqlite:///Users/RyanOConnor/workspace/testing/clublandlv.sqlite')
  24.     genre_db = DB[:genres]
  25.       genre_db.import([:genre, :genre_id], genres.zip(genre_links))
  26. end
  27.  
  28.  
  29. #The exact same script is tweaked to pull the Subgenre data. Right now I have it hardcoded to go to one of the Genre #pages which contain the Subgenre data, but I want to add a part to the script that will grab each GENRE_ID from the genres table and run the script for each.
  30.  
  31. #For example, genre links are "http://www.clublandlv.com/forumdisplay.php?f=46", where the ?F={GENREID}.
  32. # Looking at the picture, all of the entries in the Subgenres table are children of "Dirty House Music", genre_id 46.
  33. # Whatever genre_id that is currently being used, the genre name should be added to that column of the Subgenre table.
  34.  
  35.  
  36. #The songs table will have similar functionality, with tables linking to each other ON certain conditions.
Advertisement
Add Comment
Please, Sign In to add comment