Last active
March 31, 2017 20:57
-
-
Save JoseGonzalez321/3086ad4203be4e65a0f9a70da4a25dad to your computer and use it in GitHub Desktop.
First stab at F#. Inspired by https://jamessdixon.wordpress.com/2016/12/25/age-and-sex-analysis-of-microsoft-usa-mvps/
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 @"..\Packages\FSharp.Data\lib\net40\FSharp.Data.dll" | |
open System | |
open System.IO | |
open System.Web | |
open System.Net | |
open FSharp.Data | |
type Robot = JsonProvider<"http://megaman-robot-masters.herokuapp.com/"> | |
let series = 2 | |
let saveImage name avatar = | |
use client = new WebClient() | |
let path = sprintf @"C:\Playground\Images\%d\" series | |
// create directory if it doesn't exist | |
if not <| Directory.Exists(path) then | |
Directory.CreateDirectory(path) |> ignore // ignore says there's no result | |
let fullPath = sprintf "%s%s.jpg" path name | |
client.DownloadFile(Uri(avatar), fullPath) | |
printfn "Saving %s to %s ..." avatar fullPath | |
Robot.GetSamples() | |
|> Seq.filter (fun robot -> robot.Series = series) // get specific series | |
|> Seq.sortBy (fun robot -> robot.Name) // sort them for funsies | |
|> Seq.iter(fun r -> saveImage r.Name r.Avatar) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment