Created
May 10, 2016 06:46
-
-
Save hafuu/42a358aee6d4ad82101675fa7807674e to your computer and use it in GitHub Desktop.
list_fs_packages.fsx
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
| #r "System.Net.Http" | |
| #r "System.Xml" | |
| #r "System.Xml.Linq" | |
| open System | |
| open System.Net.Http | |
| open System.Xml.Linq | |
| let client = new HttpClient() | |
| let run t = t |> Async.AwaitTask |> Async.RunSynchronously | |
| let limit = fsi.CommandLineArgs.[1] |> int | |
| module Ns = | |
| let ns = XNamespace.Get("http://www.w3.org/2005/Atom") | |
| let m = XNamespace.Get("http://schemas.microsoft.com/ado/2007/08/dataservices/metadata") | |
| let d = XNamespace.Get("http://schemas.microsoft.com/ado/2007/08/dataservices") | |
| let rec listPackages (uri: Uri) = | |
| let response = client.GetAsync(uri) |> run | |
| let text = response.Content.ReadAsStringAsync() |> run | |
| let xml = XElement.Parse(text) | |
| let entries = xml.Elements(Ns.ns + "entry") | |
| let items = | |
| entries | |
| |> Seq.map (fun entry -> | |
| let name = entry.Element(Ns.ns + "title").Value | |
| let downloadCount = entry.Element(Ns.m + "properties").Element(Ns.d + "DownloadCount").Value |> int | |
| (name, downloadCount) | |
| ) | |
| match xml.Elements(Ns.ns + "link") |> Seq.tryFind (fun e -> match e.Attribute(XName.Get("rel")) with null -> false | attr -> attr.Value = "next") with | |
| | Some next -> | |
| let nextUri = Uri(next.Attribute(XName.Get("href")).Value) | |
| Seq.append items (listPackages nextUri) | |
| | None -> items | |
| Uri("https://www.nuget.org/api/v2/Search()?$filter=IsAbsoluteLatestVersion&searchTerm='tags:F%23'&includePrerelease=true") | |
| |> listPackages | |
| |> Seq.sortBy (snd >> (*)-1) | |
| |> Seq.truncate limit | |
| |> Seq.iter (fun (name, count) -> printfn "%s: %d" name count) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment