Last active
September 27, 2017 18:49
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Author
theinventor
commented
Sep 27, 2017
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