Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 49 lines (41 sloc) 1.4 kB
9b890bd @tombell Update "c" scripts help comments
tombell authored
1 # Description:
2 # Shows a short history lesson of the day from the Computer History Museum
8b915ef @facto Computer History Museum's This Day in History script
facto authored
3 #
9b890bd @tombell Update "c" scripts help comments
tombell authored
4 # Dependencies:
5 # "htmlparser": "1.7.6"
6 # "soupselect: "0.2.0"
7 #
8 # Configuration:
9 # None
10 #
11 # Commands:
12 # hubot today in computer history|tdih|chm - Displays the content from the This Day in History page on the Computer History Museum site
13 #
14 # Author:
15 # facto
16
8b915ef @facto Computer History Museum's This Day in History script
facto authored
17 Select = require("soupselect").select
18 HtmlParser = require "htmlparser"
19
20 module.exports = (robot) ->
53f7b02 @facto another fix
facto authored
21 robot.respond /(today in computer history|tdih|chm)$/i, (msg) ->
8b915ef @facto Computer History Museum's This Day in History script
facto authored
22 msg.http("http://www.computerhistory.org/tdih/")
23 .get() (err, res, body) ->
24 handler = new HtmlParser.DefaultHandler()
25 parser = new HtmlParser.Parser handler
26 parser.parseComplete body
1b353fd @facto chm script refactor
facto authored
27
410ba01 @facto chm script displays date
facto authored
28 contentEl = Select handler.dom, ".tdihevent p"
1b353fd @facto chm script refactor
facto authored
29 return unless contentEl
30 msg.send date(handler)
31 msg.send title(contentEl)
32 for sentence in blurbSentences(contentEl)
8b915ef @facto Computer History Museum's This Day in History script
facto authored
33 msg.send sentence + '.' if sentence and sentence isnt ""
1b353fd @facto chm script refactor
facto authored
34
35 title = (contentEl) ->
36 trim contentEl[0].children[0].raw
37
38 blurbSentences = (contentEl) ->
39 blurb = trim contentEl[1].children[0].raw
40 blurb.split('.')
41
42 date = (handler) ->
43 dateEl = Select handler.dom, ".title"
44 return "" unless dateEl
45 trim dateEl[0].children[0].raw
8b915ef @facto Computer History Museum's This Day in History script
facto authored
46
47 trim = (string) ->
48 return string.replace(/^\s*|\s*$/g, '')
Something went wrong with that request. Please try again.