<commit_before>class Lunch
  include Feedjira
  include Nokogiri
  include OpenURI

  def invalid_meal?(meal)
    desc = meal.content.gsub(/\s+\Z/, '')
    desc.length < 5 || desc.include?('dagens sallad')
  end

  def wday_to_date(year, week, day)
    days = %w(måndag tisdag onsdag torsdag fredag lördag söndag)
    Date.commercial(year, week, days.index(day) + 1)
  end

  def valid_date?(week, day_block)
    today = Date.today
    day = day_block.css('h3.field-label').first.content.downcase
    date = wday_to_date(today.year, week, day)
    date == today
  end

  def einstein
    url = "http://butlercatering.se/print/6"
    begin
      menu = Nokogiri.HTML(open(url))
      price = 80
      week = menu.css('h2.lunch-titel').first.content.scan(/\d/).join('').to_i
      meals = menu.css('div.field-day').select{|day| valid_date?(week, day) }.flat_map do |day|
        day.css('p').to_a.reject{|m| invalid_meal?(m) }.map do |meal|
          content = meal.content.gsub(/\s+\Z/, '')
          { title: '', summary: content, price: price }
        end
      end
      [{ name: 'Einstein', meals: meals }]
    rescue
      [{ name: 'Einstein', meals: {}}]
    end
  end

  def chalmrest
    date = Time.new.strftime("%Y-%m-%d")
    restaurants = {
      "Linsen"            => "http://intern.chalmerskonferens.se/view/restaurant/linsen/RSS%20Feed.rss?today=true&locale=#{I18n.locale.to_s}",
      "Kårrestaurangen"   => "http://intern.chalmerskonferens.se/view/restaurant/karrestaurangen/Veckomeny.rss?today=true&locale=#{I18n.locale.to_s}",
      #{}"L's kitchen"       => "http://intern.chalmerskonferens.se/view/restaurant/l-s-kitchen/Projektor.rss?today=true#{I18n.locale.to_s}",
      "Express"           => "http://intern.chalmerskonferens.se/view/restaurant/express/V%C3%A4nster.rss?today=true&locale=#{I18n.locale.to_s}"}
      #{}"<NAME>"        => "http://intern.chalmerskonferens.se/view/restaurant/j-a-pripps-pub-cafe/RSS%20Feed.rss?today=true#{I18n.locale.to_s}",
      #{}"<NAME>" => "http://intern.chalmerskonferens.se/view/restaurant/hyllan/RSS%20Feed.rss?today=true#{I18n.locale.to_s}",
      #{}"L's Resto"         => "http://intern.chalmerskonferens.se/view/restaurant/l-s-resto/RSS%20Feed.rss?today=true#{I18n.locale.to_s}",
      #{}"Kokboken"          => "http://intern.chalmerskonferens.se/view/restaurant/kokboken/RSS%20Feed.rss?today=true#{I18n.locale.to_s}"}

    restaurants.map do |key, url|
      meals = Feed.fetch_and_parse(url).entries.map do |entry|
        summary, price = entry.summary.split('@')
        summary = summary.strip
        price = price.strip

        unless summary.empty?
          { title: entry.title, summary: summary, price: price.try(&:to_i) }
        end
      end.compact

      unless meals.empty?
        { name: key, meals: meals }
      end
    end.compact
  end<commit_msg>Add ice cream marker to Einstein restaurant on fridays, fixes #165<commit_after>class Lunch
  include Feedjira
  include Nokogiri
  include OpenURI

  def invalid_meal?(meal)
    desc = meal.content.gsub(/\s+\Z/, '')
    desc.length < 5 || desc.include?('dagens sallad')
  end

  def wday_to_date(year, week, day)
    days = %w(måndag tisdag onsdag torsdag fredag lördag söndag)
    Date.commercial(year, week, days.index(day) + 1)
  end

  def valid_date?(week, day_block)
    today = Date.today
    day = day_block.css('h3.field-label').first.content.downcase
    date = wday_to_date(today.year, week, day)
    date == today
  end

  def einstein
    url = "http://butlercatering.se/print/6"
    rest_name = 'Einstein'
    rest_name = 'Einstein 🍨' if Date.today.friday?
    begin
      menu = Nokogiri.HTML(open(url))
      price = 80
      week = menu.css('h2.lunch-titel').first.content.scan(/\d/).join('').to_i
      meals = menu.css('div.field-day').select{|day| valid_date?(week, day) }.flat_map do |day|
        day.css('p').to_a.reject{|m| invalid_meal?(m) }.map do |meal|
          content = meal.content.gsub(/\s+\Z/, '')
          { title: '', summary: content, price: price }
        end
      end
      [{ name: rest_name, meals: meals }]
    rescue
      [{ name: rest_name, meals: {}}]
    end
  end

  def chalmrest
    date = Time.new.strftime("%Y-%m-%d")
    restaurants = {
      "Linsen"            => "http://intern.chalmerskonferens.se/view/restaurant/linsen/RSS%20Feed.rss?today=true&locale=#{I18n.locale.to_s}",
      "Kårrestaurangen"   => "http://intern.chalmerskonferens.se/view/restaurant/karrestaurangen/Veckomeny.rss?today=true&locale=#{I18n.locale.to_s}",
      #{}"L's kitchen"       => "http://intern.chalmerskonferens.se/view/restaurant/l-s-kitchen/Projektor.rss?today=true#{I18n.locale.to_s}",
      "Express"           => "http://intern.chalmerskonferens.se/view/restaurant/express/V%C3%A4nster.rss?today=true&locale=#{I18n.locale.to_s}"}
      #{}"<NAME>"        => "http://intern.chalmerskonferens.se/view/restaurant/j-a-pripps-pub-cafe/RSS%20Feed.rss?today=true#{I18n.locale.to_s}",
      #{}"<NAME>" => "http://intern.chalmerskonferens.se/view/restaurant/hyllan/RSS%20Feed.rss?today=true#{I18n.locale.to_s}",
      #{}"L's Resto"         => "http://intern.chalmerskonferens.se/view/restaurant/l-s-resto/RSS%20Feed.rss?today=true#{I18n.locale.to_s}",
      #{}"Kokboken"          => "http://intern.chalmerskonferens.se/view/restaurant/kokboken/RSS%20Feed.rss?today=true#{I18n.locale.to_s}"}

    restaurants.map do |key, url|
      meals = Feed.fetch_and_parse(url).entries.map do |entry|
        summary, price = entry.summary.split('@')
        summary = summary.strip
        price = price.strip

        unless summary.empty?
          { title: entry.title, summary: summary, price: price.try(&:to_i) }
        end
      end.compact

      unless meals.empty?
        { name: key, meals: meals }
      end
    end.compact
  end
{'fraction_non_alphanumeric': 0.16824359194907965, 'fraction_numerical': 0.01255805952176157, 'mean_word_length': 2.998624484181568, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '874622', 'n_tokens_mistral': 2293, 'n_tokens_neox': 2174, 'n_words': 310}