2016 Update

This commit is contained in:
Tina Müller 2016-12-05 22:15:40 +01:00
parent 948b86eafa
commit dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions

View file

@ -9,13 +9,15 @@
{{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]].
;Task:
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:
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>
...
@ -31,6 +33,7 @@ The page http://tycho.usno.navy.mil/cgi-bin/timer.pl is no longer available sinc
...
</pre>
End of comment -->
If possible, only use libraries that come at no ''extra'' monetary cost with the programming language and that are widely available and popular such as [http://www.cpan.org/ CPAN] for Perl or [[Boost]] for C++.
<br><br>

View file

@ -8,12 +8,12 @@ function getusnotime()
@sprintf "get(%s)\n => %s" url err
end
isa(s, Requests.Response) || return (s, false)
t = match(r"<BR>(.*UTC)", s.data)
isa(t, RegexMatch) || return (@sprintf("raw html:\n %s", s.data), false)
return (t.captures[1], true)
t = match(r"(?<=<BR>)(.*?UTC)", readall(s))
isa(t, RegexMatch) || return (@sprintf("raw html:\n %s", readall(s)), false)
return (t.match, true)
end
(t, issuccess) = getusnotime()
(t, issuccess) = getusnotime();
if issuccess
println("The USNO time is ", t)

View file

@ -0,0 +1,14 @@
local http = require("socket.http") -- Debian package is 'lua-socket'
function scrapeTime (pageAddress, timeZone)
local page = http.request(pageAddress)
if not page then return "Cannot connect" end
for line in page:gmatch("[^<BR>]*") do
if line:match(timeZone) then
return line:match("%d+:%d+:%d+")
end
end
end
local url = "http://tycho.usno.navy.mil/cgi-bin/timer.pl"
print(scrapeTime(url, "UTC"))

View file

@ -1,3 +1,3 @@
use HTTP::Client; # https://github.com/supernovus/perl6-http-client/
my $site = "http://tycho.usno.navy.mil/cgi-bin/timer.pl";
HTTP::Client.new.get($site).match(/'<BR>'( .+? <ws> UTC )/)[0].say
HTTP::Client.new.get($site).content.match(/'<BR>'( .+? <ws> UTC )/)[0].say

View file

@ -1,4 +1,4 @@
@(next `!wget -c http://tycho.usno.navy.mil/cgi-bin/timer.pl -O - 2> /dev/null`)
@(next @(open-command "wget -c http://tycho.usno.navy.mil/cgi-bin/timer.pl -O - 2> /dev/null"))
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final"//EN>
<html>
<body>

View file

@ -1,4 +1,4 @@
@(next `!wget -c http://tycho.usno.navy.mil/cgi-bin/timer.pl -O - 2> /dev/null`)
@(next @(open-command "wget -c http://tycho.usno.navy.mil/cgi-bin/timer.pl -O - 2> /dev/null"))
@(skip)
<BR>@time@\ UTC@(skip)
@(output)

View file

@ -0,0 +1,2 @@
set data [exec curl -s http://tycho.usno.navy.mil/cgi-bin/timer.pl]
puts [lrange [lsearch -glob -inline [split $data <BR>] *UTC*] 0 3]

View file

@ -0,0 +1,3 @@
#!/usr/bin/tcsh -f
set page = `wget -q -O- "http://tycho.usno.navy.mil/cgi-bin/timer.pl"`
echo `awk -v s="${page[22]}" 'BEGIN{print substr(s,5,length(s))}'` ${page[23]} ${page[24]}