Skip to content

Instantly share code, notes, and snippets.

@theinventor
Last active September 27, 2017 18:49
Show Gist options
  • Save theinventor/23db7c59bb1453547c4b579fe88a1451 to your computer and use it in GitHub Desktop.
Save theinventor/23db7c59bb1453547c4b579fe88a1451 to your computer and use it in GitHub Desktop.
Simple script to hit RepairShopr API and make an alarm clock - runs on raspberry pi
require 'json'
require 'time'
require "net/https"
require "uri"
# put this file in same folder; https://www.dropbox.com/s/etugzo0utqbr5gv/seatbelt.mp4?dl=0
line1 = "#{Time.now.strftime("%b %e ")}"
line2 = "#{Time.now.strftime("%l : %M %P")}"
puts `figlet #{line1}`
puts `figlet #{line2}`
matching_appointments = []
upcoming_appointments = []
date_from = (Time.now-60*60).to_s
date_to = (Time.now+60*60*48).to_s
url = "https://SUBDOMAIN.repairshopr.com/api/v1/appointments?api_key=API_KEY&include_all=true&mine=true&date_from=#{date_from}&date_to=#{date_to}"
#f = Faraday.get(url)
uri = URI.parse(URI.escape(url))
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Get.new(uri.request_uri)
response = http.request(request)
appointments = JSON.parse(response.body)['appointments']
appointments.each do |a|
start_time = Time.parse(a['start_at'])
seatbelt = "omxplayer seatbelt.mp4"
if start_time > Time.now && start_time < Time.now+15*60
matching_appointments << a['summary']
if Time.now.strftime('%M')[1] == "1"
`#{seatbelt}`
`echo "#{a['summary']}" | festival --tts`
end
puts `figlet #{a['summary']}`
elsif start_time < Time.now+60*60*8
upcoming_appointments << "[#{start_time < Time.now ? "X" : " "}] #{start_time.strftime("%l:%M%P")} #{a['summary'].to_s}"
end
end
if matching_appointments.size == 0 && upcoming_appointments.size == 0
puts "No appointments"
elsif upcoming_appointments.size > 0
upcoming_appointments.each do |a|
puts a
end
end
@theinventor
Copy link
Author

2.1.5 :029 > puts a.asciify("#{Time.now.strftime("%b %e ")}")
   _____              ___   __   
  / ____|            |__ \ / /   
 | (___   ___ _ __      ) / /_   
  \___ \ / _ \ '_ \    / / '_ \  
  ____) |  __/ |_) |  / /_ (_) | 
 |_____/ \___| .__/  |____\___/  
             | |                 
             |_|                 
 => nil 
2.1.5 :030 > puts a.asciify("#{Time.now.strftime("%l : %M %P")}")
    ___        _____  ___                    
   / _ \   _  | ____|/ _ \                   
  | (_) | (_) | |__ | | | |  _ __  _ __ ___  
   \__, |     |___ \| | | | | '_ \| '_ ` _ \ 
     / /   _   ___) | |_| | | |_) | | | | | |
    /_/   (_) |____/ \___/  | .__/|_| |_| |_|
                            | |              
                            |_|              
 => nil 
2.1.5 :031 > 

@theinventor
Copy link
Author

Get ruby on your pi - https://gist.github.com/blacktm/8302741
set your monitor resolution on your pi - https://www.raspberrypi.org/forums/viewtopic.php?t=154961

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment