class DailyRecipe::Recipe
Attributes
api_id[RW]
cook_time[RW]
name[RW]
rating[RW]
url[RW]
Public Class Methods
get_rating(api_id)
click to toggle source
# File lib/daily_recipe/Recipe.rb, line 25 def self.get_rating(api_id) #@beingy is the man gigya_api_url = "http://comments.us1.gigya.com/comments.getStreamInfo?categoryID=recipe&streamID=API_ID&includeRatingDetails=true&APIKey=3_ClDcX23A7tU8pcydnKyENXSYP5kxCbwH4ZO741ZOujPRY8Ksj2UBnj8Zopb0OX0K&sdk=js_6.3.02&format=jsonp&callback=gigya._.apiAdapters.web.callback" api_id_url = gigya_api_url.gsub("API_ID", api_id) recipe_json = Nokogiri::HTML(open(api_id_url)) part1 = recipe_json.text.gsub("gigya._.apiAdapters.web.callback(","") part2 = part1.gsub("});","}") parsed = JSON.parse(part2, symbolize_names: true) rating = parsed[:streamInfo][:avgRatings][:_overall] rating end
scrape_food_network()
click to toggle source
# File lib/daily_recipe/Recipe.rb, line 10 def self.scrape_food_network recipes = [] doc = Nokogiri::HTML(open("http://www.foodnetwork.com/recipes/photos/recipe-of-the-day-what-to-cook-now.html")) doc.search(".feed li").each do |x| recipe = self.new recipe.name = x.search("h6 a").text recipe.cook_time = x.search("dd").text recipe.api_id = (x.css("a.community-rating-stars").attribute("data-rating").value).scan(/\w+\-.+\w+/).join("-") recipe.url = @base_url + x.search(".community-rating-stars").attribute("href").value recipe.rating = get_rating(recipe.api_id) recipes << recipe end recipes end
scrape_full_recipe(the_recipe)
click to toggle source
# File lib/daily_recipe/Recipe.rb, line 36 def self.scrape_full_recipe(the_recipe) doc = Nokogiri::HTML(open(the_recipe.url)) ingredients = doc.search("div.ingredients li") puts "" puts "Ingredients" ingredients.each do |ingredient| puts ingredient.text end cooking_instructions = doc.search("div.directions li") cooking_instructions.each do |instruction| puts "" puts instruction.text end end
today()
click to toggle source
# File lib/daily_recipe/Recipe.rb, line 6 def self.today self.scrape_food_network end