Created
October 15, 2014 06:57
-
-
Save jbavari/332bb7e8186f8de67c5b to your computer and use it in GitHub Desktop.
Hubot script for felony football
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here are some possible command ideas: