Skip to content

Commit

Permalink
Merge pull request #240 from amplifying-fsharp/blue-hair
Browse files Browse the repository at this point in the history
Blue hair
  • Loading branch information
nojaf authored Apr 2, 2024
2 parents 3b67948 + cd99fa3 commit 655ba36
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
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 655ba36

Please sign in to comment.