Task

Create a program that downloads the time from this URL:   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. Alternatively, if the above url is not working, grab the first date/time off this page's talk page.



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 CPAN for Perl or Boost for C++.




 
Class Utils.Net [ Abstract ]
{
 
ClassMethod ExtractHTMLData(pHost As %String = "", pPath As %String = "", pRegEx As %String = "", Output list As %List) As %Status
{
  // implement error handling
  Try {
 
    // some initialisation
    Set list="", sc=$$$OK
 
    // check input parameters
    If $Match(pHost, "^([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,6}$")=0 {
      Set sc=$$$ERROR($$$GeneralError, "Invalid host name.")
      Quit
    }
 
    // create http request and get page
    Set req=##class(%Net.HttpRequest).%New()
    Set req.Server=pHost
    Do req.Get(pPath)
 
    // check for success
    If $Extract(req.HttpResponse.StatusCode)'=2 {
      Set sc=$$$ERROR($$$GeneralError, "Page not loaded.")
      Quit
    }
 
    // read http response stream
    Set html=req.HttpResponse.Data
    Set html.LineTerminator=$Char(10)
    Set sc=html.Rewind()
 
    // read http response stream
    While 'html.AtEnd {
      Set line=html.ReadLine(, .sc, .eol)
      Set pos=$Locate(line, pRegEx)
      If pos {
        Set parse=$Piece($Extract(line, pos, *), $Char(9))
        Set slot=$ListLength(list)+1
        Set $List(list, slot)=parse
      }
    }
 
  } Catch err {
 
    // an error has occurred
    If err.Name="<REGULAR EXPRESSION>" {
      Set sc=$$$ERROR($$$GeneralError, "Invalid regular expression.")
    } Else {
      Set sc=$$$ERROR($$$CacheError, $ZError)
    }
 
  }
 
  // return status
  Quit sc
}
 
}
 