September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
|
|
@ -1,39 +0,0 @@
|
|||
http = require 'http'
|
||||
|
||||
CONFIG =
|
||||
host: 'tycho.usno.navy.mil'
|
||||
path: '/cgi-bin/timer.pl'
|
||||
|
||||
# Web scraping code tends to be brittle, and this is no exception.
|
||||
# The tycho time page does not use highly structured markup, so
|
||||
# we do a real dirty scrape.
|
||||
scrape_tycho_ust_time = (text) ->
|
||||
for line in text.split '\n'
|
||||
matches = line.match /(.*:\d\d UTC)/
|
||||
if matches
|
||||
console.log matches[0].replace '<BR>', ''
|
||||
return
|
||||
throw Error("unscrapable page!")
|
||||
|
||||
# This is low-level-ish code to get data from a URL. It's
|
||||
# pretty general purpose, so you'd normally tuck this away
|
||||
# in a library (or use somebody else's library).
|
||||
wget = (host, path, cb) ->
|
||||
options =
|
||||
host: host
|
||||
path: path
|
||||
headers:
|
||||
"Cache-Control": "max-age=0"
|
||||
|
||||
req = http.request options, (res) ->
|
||||
s = ''
|
||||
res.on 'data', (chunk) ->
|
||||
s += chunk
|
||||
res.on 'end', ->
|
||||
cb s
|
||||
req.end()
|
||||
|
||||
# Do our web scrape
|
||||
do ->
|
||||
wget CONFIG.host, CONFIG.path, (data) ->
|
||||
scrape_tycho_ust_time data
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
> coffee web_scrape.coffee
|
||||
Jan. 09, 19:19:07 UTC
|
||||
Loading…
Add table
Add a link
Reference in a new issue