Skip to content

Instantly share code, notes, and snippets.

@Ellyll
Last active Mar 16, 2020
Embed
What would you like to do?
F# console app to get Corona virus data for Wales by county
open FSharp.Data
[<Literal>]
let SampleUrl = "file://" + __SOURCE_DIRECTORY__ + "/Sample.html"
[<Literal>]
let PageUrl = "https://phw.nhs.wales/news/public-health-wales-statement-on-novel-coronavirus-outbreak/"
type Page = HtmlProvider<SampleUrl>
[<EntryPoint>]
let main argv =
let page = Page.Load(PageUrl)
let rows = page.Tables.Table1.Rows
let authorityData =
rows
|> Array.take 22
|> Array.map (fun row ->
let authority = row.``Local Authority``
let cases = row.``Total number of cases as of 11am, 16 March``
authority, cases)
let toBeConfirmed = (rows |> Array.skip 22 |> Array.head).``Total number of cases as of 11am, 16 March``
let outsideWales = (rows |> Array.skip 23 |> Array.head).``Total number of cases as of 11am, 16 March``
let total = (rows |> Array.last).``Total number of cases as of 11am, 16 March``
authorityData
|> Array.sortBy (fun (authority, cases) -> -cases, authority)
|> Array.iter (fun (authority, cases) -> printfn "%s: %i" authority cases)
printfn "Area to be confirmed: %i" toBeConfirmed
printfn "Resident outside Wales: %i" outsideWales
printfn "Total: %i" total
0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment