Skip to content
Fetching contributors…
Cannot retrieve contributors at this time
37 lines (30 sloc) 1.22 KB
# Shows a short history lesson of the day from the Computer History Museum.
# today in computer history|tdih|chm - Displays the content from the This Day in History page on the Computer History Museum site.
Select = require("soupselect").select
HtmlParser = require "htmlparser"
module.exports = (robot) ->
robot.respond /(today in computer history|tdih|chm)$/i, (msg) ->
.get() (err, res, body) ->
handler = new HtmlParser.DefaultHandler()
parser = new HtmlParser.Parser handler
parser.parseComplete body
contentEl = Select handler.dom, ".tdihevent p"
return unless contentEl
msg.send date(handler)
msg.send title(contentEl)
for sentence in blurbSentences(contentEl)
msg.send sentence + '.' if sentence and sentence isnt ""
title = (contentEl) ->
trim contentEl[0].children[0].raw
blurbSentences = (contentEl) ->
blurb = trim contentEl[1].children[0].raw
date = (handler) ->
dateEl = Select handler.dom, ".title"
return "" unless dateEl
trim dateEl[0].children[0].raw
trim = (string) ->
return string.replace(/^\s*|\s*$/g, '')
Something went wrong with that request. Please try again.