Skip to content

Instantly share code, notes, and snippets.

@lucasteles
Last active November 9, 2023 19:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lucasteles/44db6b7cdff1cc0f5ea97944d085278c to your computer and use it in GitHub Desktop.
Save lucasteles/44db6b7cdff1cc0f5ea97944d085278c to your computer and use it in GitHub Desktop.
Capcom Sells FSharp
#r "nuget: FSharp.Data"
#r "nuget: Humanizer.Core"
#r "nuget: EluciusFTW.SpectreCoff"
open FSharp.Data
open SpectreCoff
open Humanizer
open System
open System.Globalization
open Spectre.Console
CultureInfo.CurrentCulture <- CultureInfo.InvariantCulture
module Capcom =
[<Literal>]
let CAPCOM_SELLS_URL =
"https://www.capcom.co.jp/ir/english/business/million.html#tab6"
type CapcomSells = HtmlProvider<CAPCOM_SELLS_URL>
let table = CapcomSells.GetSample().Tables.Table1
let sells =
table.Rows
|> Seq.toList
|> List.map (fun v ->
{| Release = DateOnly.FromDateTime v.Release
Title = v.Title.Split('*').[0].Trim()
Platforms = v.Platform.Split(',', StringSplitOptions.TrimEntries) |> Array.toList
MillionUnits = v.``Million units``.Replace("※", "") |> decimal |})
let showGame (terms: string list) =
let sells =
Capcom.sells
|> List.filter (fun r ->
terms |> List.isEmpty
|| terms
|> Seq.exists (fun game -> r.Title.Contains(game, StringComparison.OrdinalIgnoreCase)))
Many
[ BlankLine
calm $"Searched terms ({sells.Length})" |> alignedRule Left
BlankLine
BulletItems
[ for term in terms do
Many
[ MarkupC(Color.Yellow, term.Humanize(LetterCasing.Title))
Pumped(
sells
|> List.filter (fun r -> r.Title.Contains(term, StringComparison.OrdinalIgnoreCase))
|> List.length
|> string
) ] ]
table
[ column (Edgy "Title")
column (Edgy "Release")
column (Edgy "Platforms")
column (Edgy "Million Units") ]
[ for sell in sells do
Payloads
[ Vanilla sell.Title
Pumped(sell.Release.ToOrdinalWords().Replace(" 1st", ""))
Calm(sell.Platforms |> String.concat ",")
MarkupCD(Color.Green, [ Decoration.Bold ], string sell.MillionUnits) ] ]
|> withTitle $"{Emoji.Known.Joystick} [b][red]Sells[/][/] {Emoji.Known.Joystick}"
|> toOutputPayload ]
|> toConsole
showGame [ "street fighter"; "marvel vs." ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment