[bitbar] Initial commit of BitBar stuff
change
commit 1f1ed4cc116a9a6054f1f6d8ded93373ca0062c8
author Alpha Chen <alpha.chen@gmail.com>
date
parent acd00004
diff --git a/Rakefile b/Rakefile
index 23eb9ed4..4efe4587 100644
--- a/Rakefile
+++ b/Rakefile
@@ -50,3 +50,18 @@ namespace :sync do
     # end
   end
 end
+
+namespace :bitbar do
+  FILE = 'onebusaway.30s.rb'
+
+  desc 'Toggle OneBusAway BitBar plugin'
+  task :oba do
+    if File.exist?(File.expand_path("../bitbar/enabled/#{FILE}", __FILE__))
+      rm File.expand_path("../bitbar/enabled/#{FILE}", __FILE__)
+    else
+      ln_s File.expand_path("../bitbar/#{FILE}", __FILE__),
+           File.expand_path("../bitbar/enabled/#{FILE}", __FILE__)
+    end
+    sh 'open bitbar://refreshPlugin?name=onebusaway.*'
+  end
+end
diff --git a/ansible/roles/homebrew/vars/main.yml b/ansible/roles/homebrew/vars/main.yml
index 5cf6625f..bbb10a2d 100644
--- a/ansible/roles/homebrew/vars/main.yml
+++ b/ansible/roles/homebrew/vars/main.yml
@@ -18,9 +18,9 @@ casks:
   - acorn
   - adium
   - alfred
-  # - anybar
   - arq
   - bartender
+  - bitbar
   - bittorrent-sync
   - black-ink
   - dash
diff --git a/bitbar/.gitignore b/bitbar/.gitignore
new file mode 100644
index 00000000..4c60de9a
--- /dev/null
+++ b/bitbar/.gitignore
@@ -0,0 +1,2 @@
+vendor
+enabled
diff --git a/bitbar/.ruby-version b/bitbar/.ruby-version
new file mode 100644
index 00000000..227cea21
--- /dev/null
+++ b/bitbar/.ruby-version
@@ -0,0 +1 @@
+2.0.0
diff --git a/bitbar/Gemfile b/bitbar/Gemfile
new file mode 100644
index 00000000..b6bbf79a
--- /dev/null
+++ b/bitbar/Gemfile
@@ -0,0 +1,5 @@
+source 'https://rubygems.org'
+
+group :development do
+  gem 'pry'
+end
diff --git a/bitbar/Gemfile.lock b/bitbar/Gemfile.lock
new file mode 100644
index 00000000..b5d163ea
--- /dev/null
+++ b/bitbar/Gemfile.lock
@@ -0,0 +1,19 @@
+GEM
+  remote: https://rubygems.org/
+  specs:
+    coderay (1.1.1)
+    method_source (0.8.2)
+    pry (0.10.3)
+      coderay (~> 1.1.0)
+      method_source (~> 0.8.1)
+      slop (~> 3.4)
+    slop (3.6.0)
+
+PLATFORMS
+  ruby
+
+DEPENDENCIES
+  pry
+
+BUNDLED WITH
+   1.11.2
diff --git a/bitbar/Rakefile b/bitbar/Rakefile
new file mode 100644
index 00000000..4457b61a
--- /dev/null
+++ b/bitbar/Rakefile
@@ -0,0 +1,5 @@
+desc ''
+task :bundle do
+  cmd = 'bundle install --standalone --path vendor/bundle --without development test'
+  sh "chruby-exec 2.0.0 -- #{cmd}"
+end
diff --git a/bitbar/onebusaway.30s.rb b/bitbar/onebusaway.30s.rb
new file mode 100755
index 00000000..77b00fba
--- /dev/null
+++ b/bitbar/onebusaway.30s.rb
@@ -0,0 +1,30 @@
+#!/usr/bin/env ruby
+
+require 'open-uri'
+require 'rexml/document'
+
+COLOR_MAP = {
+  arrivalStatusOnTime: :green,
+  arrivalStatusNoInfo: :black,
+  arrivalStatusEarly: :red,
+  arrivalStatusDelayed: :blue,
+  arrivalStatusDepartedOnTime: :green,
+  arrivalStatusDepartedNoInfo: :black,
+  arrivalStatusDepartedEarly: :red,
+  arrivalStatusDepartedDelayed: :blue,
+  arrivalStatusCancelled: :red,
+}
+
+html = open('http://pugetsound.onebusaway.org/where/standard/stop.action?id=1_7360').read
+doc = REXML::Document.new(html)
+status = doc.elements['//td[contains(@class, "arrivalsStatusEntry")]']
+
+minutes = status.elements['//span'].text
+color = COLOR_MAP[status.attributes['class'].split(/\s+/).last.to_sym]
+times = doc.elements.to_a('//div[@class="arrivalsTimePanel"]')
+
+puts "#{minutes} | color=#{color}"
+puts '---'
+times.each do |time|
+  puts "#{time[0].text}#{time[1]}#{time[2].text}"
+end