Skip to content

Instantly share code, notes, and snippets.

@camillebaldock
Created October 17, 2015 19:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save camillebaldock/dba41bf241de0d71b6fb to your computer and use it in GitHub Desktop.
Save camillebaldock/dba41bf241de0d71b6fb to your computer and use it in GitHub Desktop.
Dashing GoWatchIt

Description

A Dashing widget for displaying the number of films in my GoWatchIt for an account.

See a live demo here.

Usage

Due to the fact that GoWatchIt does not, at current time of writing, have a public API, I wrote some code to scrape the data off their webpage.

I decided to run the script on a personal machine at home and push the data to my Dashing application.

Setup the following environment variables:

  • GO_WATCH_IT_USER
  • GO_WATCH_IT_PASSWORD
  • AUTH_TOKEN: the auth token of your Dashing application

Dependencies

watir-webdriver

Add it to your Dashing application's Gemfile:

gem 'watir-webdriver'

and run bundle install.

require 'watir-webdriver'
Selenium::WebDriver::Firefox::Binary.path=ENV["FIREFOX_PATH"]
class GoWatchItClient
def initialize(user, password)
@user = user
@password = password
@browser = Watir::Browser.new :firefox
end
def number_in_queue
@browser.goto "http://gowatchit.com/users/sign_in"
@browser.text_field(:name => 'user[email]').set(@user)
@browser.text_field(:name => 'user[password]').set(@password)
@browser.element(:css => '#login').click
number = @browser.element(:css => "#movie_count").text.to_i
@browser.close
number
end
end
client = GoWatchItClient.new(ENV["GO_WATCH_IT_USER"], ENV["GO_WATCH_IT_PASSWORD"])
auth_token=ENV["AUTH_TOKEN"]
json_headers = {"Content-Type" => "application/json",
"Accept" => "application/json"}
number = client.number_in_queue
p "#{number} films"
params = {'auth_token' => auth_token, 'current' => number }
uri = URI.parse('http://'+ENV["DASHBOARD_URL"]+'/widgets/go_watch_it')
http = Net::HTTP.new(uri.host, uri.port)
response = http.post(uri.path, params.to_json, json_headers)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment