Installing and using F#
https://swlaschin.gitbooks.io/fsharpforfunandprofit/content/installing-and-using/
Last updated
https://swlaschin.gitbooks.io/fsharpforfunandprofit/content/installing-and-using/
Last updated
// ================================
// Description:
// downloads the given url and stores it as a file with a timestamp
//
// Example command line:
// fsi ShellScriptExample.fsx http://google.com google
// ================================
// "open" brings a .NET namespace into visibility
open System.Net
open System
// download the contents of a web page
let downloadUriToFile url targetfile =
let req = WebRequest.Create(Uri(url))
use resp = req.GetResponse()
use stream = resp.GetResponseStream()
use reader = new IO.StreamReader(stream)
let timestamp = DateTime.UtcNow.ToString("yyyy-MM-ddTHH-mm")
let path = sprintf "%s.%s.html" targetfile timestamp
use writer = new IO.StreamWriter(path)
writer.Write(reader.ReadToEnd())
printfn "finished downloading %s to %s" url path
// Running from FSI, the script name is first, and other args after
match fsi.CommandLineArgs with
| [| scriptName; url; targetfile |] ->
printfn "running script: %s" scriptName
downloadUriToFile url targetfile
| _ ->
printfn "USAGE: [url] [targetfile]"dotnet fsi ShellScriptExample.fsx http://google.com google_homepage