Skip to content

Instantly share code, notes, and snippets.

@alexbaldwin
Created October 26, 2016 05:02
Show Gist options
  • Save alexbaldwin/2894fb8ee02c2c609bfbb81e7fbe2b3a to your computer and use it in GitHub Desktop.
Save alexbaldwin/2894fb8ee02c2c609bfbb81e7fbe2b3a to your computer and use it in GitHub Desktop.
Posts the Warriors Score if there's a current game
require 'awesome_print'
require 'faraday'
require 'twitter'
require 'json'
require 'date'
require 'time'
date = Time.now.strftime("%Y%m%d")
url = "http://data.nba.net/data/10s/prod/v1/#{date}/scoreboard.json"
client = Twitter::REST::Client.new do |config|
config.consumer_key = ""
config.consumer_secret = ""
config.access_token = ""
config.access_token_secret = ""
end
conn = Faraday.new(:url => url) do |faraday|
faraday.request :url_encoded # form-encode POST params
faraday.response :logger # log requests to STDOUT
faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
end
response = conn.get
results = JSON.parse(response.body)
games = results['games']
games.each do |game|
home = game['hTeam']['triCode']
away = game['vTeam']['triCode']
home_score = game['hTeam']['score']
away_score = game['vTeam']['score']
playing = (game['clock'] != "")
if playing
if home == "GSW" || away == "GSW"
ap message = "#{period} #{clock} #{home} #{home_score} − #{away} #{away_score} #DubNation"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment