Guest User

Untitled

a guest
Jun 18th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. require 'csv'
  2. require "date"
  3. require 'ruby_gntp'
  4.  
  5. data = CSV.read("TimeTable.csv")
  6.  
  7. data.map! { |item| [item[0].to_i,item[1..item.length].map! { |i| i.to_i } ] }
  8.  
  9. table = Hash[*data.flatten(1)]
  10.  
  11.  
  12. dn = DateTime.now
  13. n_hour = dn.hour.to_i
  14. n_min = dn.min.to_i
  15.  
  16. t_hour = n_min <= 40 ? n_hour : (n_hour + 1)%24
  17. t_min = n_min <= 40 ? n_min+20 : n_min-40
  18.  
  19.  
  20. if table[t_hour].index(t_min) != nil then
  21.  
  22. GNTP.notify(
  23. :app_name => "NoticeTrain",
  24. :title => "20分前通知",
  25. :text => t_hour.to_s+"時"+t_min.to_s+"分の電車まであと20分です",
  26. :icon => "",
  27. :sticky=> false,
  28. )
  29.  
  30. end
Add Comment
Please, Sign In to add comment