-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreateDailyJsons.fsx
More file actions
54 lines (44 loc) · 1.73 KB
/
CreateDailyJsons.fsx
File metadata and controls
54 lines (44 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Uses NYTGames to download the solutions to all of today's games as JSON files
#r "NYTGames/bin/Debug/net9.0/NYTGames.dll"
#r "nuget: Thoth.Json.Net"
#r "nuget: FSharp.Data"
#r "nuget: ObjectDumper.Net"
open NYTGames
open System
open System.IO
open Thoth.Json.Net
open Newtonsoft.Json
let dateStamp = DateTime.Now |> Helpers.formatDate
/// Formats a json string with an indent level of 4
/// <seealso cref="https://www.newtonsoft.com/json/help/html/T_Newtonsoft_Json_JsonTextWriter.htm" />
let formatJson json =
use sr = new StringReader(json)
use jr = new JsonTextReader(sr)
use sw = new StringWriter()
// This is where Newtonsoft.Json exposes the most formatting settings
use jw = new JsonTextWriter(sw, Formatting = Formatting.Indented, Indentation = 4)
jw.WriteToken(jr)
sw.ToString()
let dumpResult filename object =
async {
let! res = object
let json = res |> Result.assertOk |> Encode.Auto.toString |> formatJson
return!
File.WriteAllTextAsync($"Raw/%s{dateStamp}.%s{filename}.json", json)
|> Async.AwaitTask
}
// Exports
[
Game.Wordle.getCurrentGame () |> dumpResult "wordle"
Game.Connections.getCurrentGame () |> dumpResult "connections"
Game.ConnectionsSports.getCurrentGame () |> dumpResult "connections-sports"
Game.Strands.getCurrentGame () |> dumpResult "strands"
Game.LetterBoxed.getCurrentGame () |> dumpResult "letter-boxed"
Game.TheMini.getCurrentGame () |> dumpResult "the-mini"
Game.TheCrossword.getCurrentGame () |> dumpResult "the-crossword"
Game.SpellingBee.getCurrentGame () |> dumpResult "spelling-bee"
Game.Suduko.getCurrentGame () |> dumpResult "suduko"
]
|> Async.Parallel
|> Async.RunSynchronously
|> ignore