From 70903ec124c164d68f77206abb77d8198f9a4b68 Mon Sep 17 00:00:00 2001 From: Wataru Otsubo Date: Thu, 3 Oct 2024 11:52:59 +0900 Subject: [PATCH] add interactive dispatch_checker - TODO: add test! --- src/dispatch_checker.jl | 62 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/src/dispatch_checker.jl b/src/dispatch_checker.jl index 089130e..b9e2094 100644 --- a/src/dispatch_checker.jl +++ b/src/dispatch_checker.jl @@ -68,4 +68,66 @@ function is_dispatchable(conn::DbConnection, psbid::Int64) return missing end +function interactive_dispatch_checker(conn::DbConnection) + dispatch_list = Int64[] + + println("Type \"quit\" to exit") + for _ in 1:1000 + printstyled("PSBoard ID: ", bold = true) + psbid = let + rawin = readline() + if lowercase(rawin) == "quit" + printstyled("Quit\n", italic = true) + println() + break + end + m = match(r"^PS(\d+)", rawin) + if isnothing(m) + printstyled("Invalid input\n", color = :red) + continue + end + parse(Int64, m[1]) + end + isdispatchable = is_dispatchable(conn, psbid) + if ismissing(isdispatchable) + printstyled("Please determine [y/n]: ", underline = true, color = :cyan) + isdispatchable = let + rawin = readline() + @info "" rawin + if rawin == "y" || rawin == "Y" + true + elseif rawin == "n" || rawin == "N" + false + else + @warn "Invalid input falling back to \"no\"" + false + end + end + end + if isdispatchable + printstyled("Ok\n", bold = true, color = :green) + if psbid in dispatch_list + println("PSBoard ID $(psbid) is already in dispatch list") + else + push!(dispatch_list, psbid) + println("Added to dispatch list") + end + else + printstyled("No\n", bold = true, color = :red) + end + end + + printstyled("Finished\n") + join(dispatch_list, "\n") |> print + println() + printstyled("Paste the result", underline = true) + + return dispatch_list +end + +function interactive_dispatch_checker(database_file::AbstractString) + conn = DbConnection(SQLite.DB(database_file)) + interactive_dispatch_checker(conn) +end + end # module DispatchChecker