Skip to content

Commit

Permalink
Add simple script for blue hair
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf committed Mar 20, 2024
1 parent 1f22452 commit e392311
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions blue-hair.fsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#r "nuget: FsHttp"

open System.Collections.Generic
open FsHttp

Fsi.disableDebugLogs ()

type Transaction = {| createdByUser: obj; amount: int |}
type OpenCollectiveResponse = {| result: Transaction array |}

let openCollectiveResponse =
http {
GET
"https://opencollective.com/v1/collectives/amplifying-fsharp/transactions?dateFrom=2024-01-01&dateTo=2024-12-31"

CacheControl "no-cache"
}
|> Request.send
|> Response.deserializeJson<OpenCollectiveResponse>

let total =
openCollectiveResponse.result
|> Array.map (fun t -> if isNull t.createdByUser then 0 else t.amount)
|> Array.sum
|> fun sum -> sum / 100

printfn "Total collected: $%i" total

type ExchangeRateResponse = {| rates: Dictionary<string, float> |}

let exchangeRateResponse =
http {
GET "https://api.frankfurter.app/latest?from=USD&to=GBP"
CacheControl "no-cache"
}
|> Request.send
|> Response.deserializeJson<ExchangeRateResponse>

let rate = exchangeRateResponse.rates.["GBP"]
printfn "Current exchange rate $ to £: %.02f" rate

let totalInPounds = float total * rate

if totalInPounds > 5000 then
printfn $"Edgar should have blue hair, raised £%f{totalInPounds}"
else
printfn $"No blue hair yet, currently at £%.02f{totalInPounds}"

0 comments on commit e392311

Please sign in to comment.