Skip to content

Instantly share code, notes, and snippets.

@JoseGonzalez321
Last active March 31, 2017 20:57
Show Gist options
  • Save JoseGonzalez321/3086ad4203be4e65a0f9a70da4a25dad to your computer and use it in GitHub Desktop.
Save JoseGonzalez321/3086ad4203be4e65a0f9a70da4a25dad to your computer and use it in GitHub Desktop.
#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