Just another update

This commit is contained in:
Ingy döt Net 2015-02-20 00:35:01 -05:00
parent a25938f123
commit 00a190b0a6
6591 changed files with 94363 additions and 23227 deletions

View file

@ -1,11 +1,22 @@
{{omit from|ACL2|Does not have network access.}}
{{omit from|Batch File|Does not have network access.}}
{{omit from|Locomotive Basic|Does not have network access.}}
{{omit from|Lotus 123 Macro Scripting}}
{{omit from|M4}}
{{omit from|Maxima}}
{{omit from|Openscad}}
{{omit from|PARI/GP}}
{{omit from|PostScript|no network access}}
{{omit from|Retro|Does not have network access.}}
{{omit from|ZX Spectrum Basic|Does not have network access.}}
Create a program that downloads the time from this URL: [http://tycho.usno.navy.mil/cgi-bin/timer.pl http://tycho.usno.navy.mil/cgi-bin/timer.pl] and then prints the current UTC time by extracting just the UTC time from the web page's [[HTML]].
<!-- As of March 2014, the page is available
{{task|Networking and Web Interaction}}
The page http://tycho.usno.navy.mil/cgi-bin/timer.pl is no longer available since july 2011. The relevant part of that page source looked like this:
<pre>
...
<TITLE>What time is it?</TITLE>
@ -19,7 +30,6 @@ The page http://tycho.usno.navy.mil/cgi-bin/timer.pl is no longer available sinc
<BR>Jul. 27, 12:57:22 PM HAST Hawaii-Aleutian Time
...
</pre>
End of comment -->

View file

@ -1,2 +1,4 @@
---
note: Networking and Web Interaction
category:
- Input_Output
note: Networking

View file

@ -0,0 +1,39 @@
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

View file

@ -0,0 +1,7 @@
var req = new XMLHttpRequest();
req.onload = function () {
var re = /[JFMASOND].+ UTC/; //beginning of month name to 'UTC'
console.log(this.responseText.match(re)[0]);
};
req.open('GET', 'http://tycho.usno.navy.mil/cgi-bin/timer.pl', true);
req.send();