Last active
December 27, 2015 05:19
-
-
Save lobrien/7273287 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let GetAsync(url : string, i : int) = | |
async { | |
let req = WebRequest.Create(url) | |
let! rsp = req.AsyncGetResponse() | |
use stream = (rsp :?> HttpWebResponse).GetResponseStream() | |
use zip = new GZipStream(stream, CompressionMode.Decompress) | |
use reader = new StreamReader(zip) | |
Console.WriteLine("Received page " + i.ToString()) | |
return reader.ReadToEnd() | |
} | |
let FetchData(maxPage : int) : JsonValue[] = | |
[1..maxPage] | |
|> Seq.map( fun i -> GetAsync(UrlForPage(i), i)) | |
|> Async.Parallel | |
|> Async.RunSynchronously | |
|> Seq.map (fun json -> JsonValue.Parse(json)) | |
...etc... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
We can do better :)