diff --git a/README.md b/README.md index 156b5f1..f25418d 100644 --- a/README.md +++ b/README.md @@ -75,6 +75,12 @@ We have an [Open Collective](https://opencollective.com/amplifying-fsharp#catego ![Vagif Abilov](https://www.gravatar.com/avatar/822d40ce216f2d64bcc2c59f0ded1e4d?default=404&s=50) [Vagif Abilov](https://opencollective.com/vagif-abilov) +### Blue hair + +```shell +dotnet fsi blue-hair.fsx +``` + ## The website source code ### Requirements diff --git a/blue-hair.fsx b/blue-hair.fsx new file mode 100644 index 0000000..c33afcf --- /dev/null +++ b/blue-hair.fsx @@ -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 + +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 |} + +let exchangeRateResponse = + http { + GET "https://api.frankfurter.app/latest?from=USD&to=GBP" + CacheControl "no-cache" + } + |> Request.send + |> Response.deserializeJson + +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}"