Skip to content

Instantly share code, notes, and snippets.

@jbavari
Created October 15, 2014 06:57
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 jbavari/332bb7e8186f8de67c5b to your computer and use it in GitHub Desktop.
Save jbavari/332bb7e8186f8de67c5b to your computer and use it in GitHub Desktop.
Hubot script for felony football
# Description:
# Make hubot fetch the national felony football scores
#
# Dependencies:
# "cheerio": "^0.17.0"
#
# Configuration:
# None
#
# Commands:
# felony football scoreboard
# Author:
# jbavari
cheerio = require 'cheerio'
$ = null
teams = {}
# teams = { '2014': { 'DAL': 1 }, '2013': { 'DAL': 3 } }
# item is <tr> element. 1st child is date, 2nd is team short name
getTeamCounts = (index, item) ->
# console.log('index: ', index, ' item: ', item)
year = $(item).find('td:nth-child(1)').html().substring(0, 4)
# console.log('year: ', year)
if typeof teams[year] == 'undefined'
teams[year] = {}
teamAtr = $(item).find('td:nth-child(2)').html()
# console.log('teamAtr: ', teamAtr)
teamCount = teams[year][teamAtr]
# console.log('team count: ', teamCount)
if typeof teamCount == 'undefined'
teams[year][teamAtr] = 0;
# console.log('initing team count ' , teamAtr)
else
teamCount = teamCount + 1
# console.log('added 1 to team count for ', teamAtr)
teams[year][teamAtr] = teamCount
module.exports = (robot) ->
robot.hear /felony football/i, (msg) ->
robot.http('http://www.usatoday.com/sports/nfl/arrests/')
.get() (err, res, body) ->
$ = cheerio.load(body)
# console.log('jquery : ' , $)
throw err if err
# $('tbody tr').remove()
# $('tbody tr td:nth-child(2)').each(getTeamCounts)
$('tbody tr').each(getTeamCounts)
msg.send JSON.stringify(teams)
@ryoe
Copy link

ryoe commented Oct 15, 2014

Here are some possible command ideas:

  • hubot nfl arrests <year> - show nfl arrests for the given year. if no year, show all.
  • hubot nfl arrests <year> <team> - show nfl arrests for the given year, by team.
  • hubot nfl arrests team <team> - show nfl arrests for the team.
  • hubot nfl arrests details <team> - show nfl arrests for the team with player details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment