From 0776c1c05e23949eeabad9c0eaeca41ee9b7d68b Mon Sep 17 00:00:00 2001 From: Jon Date: Thu, 15 Aug 2019 08:07:04 -0400 Subject: [PATCH] Script to send a message when we scrape the site. --- README.md | 7 +++++++ lunch_announcements.rb | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100755 lunch_announcements.rb diff --git a/README.md b/README.md index 9ceaee9..b4206fb 100644 --- a/README.md +++ b/README.md @@ -7,3 +7,10 @@ A very specific utility for scraping my eldest son's elementary school lunch men * Ruby * Nokogiri / Watir * [chrome webdriver](https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver) + +## ENV vars required: + +* TO - the numbers to send to, comma delimited +* FROM - the Twilio number to send from +* TWILIO_ACCOUNT_SID - The Twilio Account SID +* TWILIO_AUTH_TOKEN - The Twilio secret auth token diff --git a/lunch_announcements.rb b/lunch_announcements.rb new file mode 100755 index 0000000..7b22525 --- /dev/null +++ b/lunch_announcements.rb @@ -0,0 +1,34 @@ +#!/usr/bin/env ruby +# coding: utf-8 +# +# Send a Lunch Announcement. +# +# ENV vars required: +# - TO - the numbers to send to, comma delimited +# - FROM - the Twilio number to send from +# - TWILIO_ACCOUNT_SID - The Twilio Account SID +# - TWILIO_AUTH_TOKEN - The Twilio secret auth token +require 'date' +require 'twilio-ruby' +require_relative 'lib/lunch_scraper' + +REQUIRED_ENV = %w(TO FROM TWILIO_ACCOUNT_SID TWILIO_AUTH_TOKEN).freeze + +REQUIRED_ENV.each do |req| + raise "Missing ENV var #{req}" if ENV[req].nil? +end + +lunch = LunchScraper.new(Date.today) +menu = lunch.today + +client = Twilio::REST::Client.new(ENV['TWILIO_ACCOUNT_SID'], ENV['TWILIO_AUTH_TOKEN']) + +destinations = ENV['FROM'].split(',') + +destinations.each do |to| + client.messages.create( + from: ENV['FROM'], + to: to, + body: "TODAY'S FOUSE LUNCH MENU:\n\n#{menu.join("\n")}\n\n❤ Lunchbot️️️" + ) +end