;download-xml-forecast.scm: download current xml forecast for SLC from noaa site, ;and save it to a file named according to current date. (require (lib "url.ss" "net")) (define noaa-string "http://www1.wrh.noaa.gov/cgi-bin/dwf?outFormat=xml&duration=168hr&interval=12&citylist=Select+City%2C%2Cnone&latitude=&longitude=&ZOOMLEVEL=8&XSTART=220&YSTART=368&XC=246&YC=401&X=246&Y=401&siteID=SLC&click.x=206&click.y=248") (define url:noaa (string->url noaa-string)) (define i (get-pure-port url:noaa)) ; date->filename : date -> string ; make "{year}{month}{day}" string for output filename (define (date->filename d) (let ((number->paddedstring (lambda(n) (cond [(< n 10) (string-append "0" (number->string n))] [else (number->string n)])))) (apply string-append (map number->paddedstring (list (date-year d) (date-month d) (date-day d)))))) (define o (open-output-file (string-append (date->filename (seconds->date (current-seconds))) ".xml"))) (define (copy-files input-port output-port) (let ((c (read-char input-port))) (cond [(not (eof-object? c)) (write-char c output-port) (copy-files input-port output-port)]))) (copy-files i o) (close-output-port o)