From fedf524a9679c08faa2aa1130546c9162fb9780a Mon Sep 17 00:00:00 2001 From: Andrii Kurdiumov Date: Mon, 18 Nov 2024 19:22:59 +0500 Subject: [PATCH] Add sample in F# --- TelegramExportProcessor.sln | 1 + sample.fsx | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 sample.fsx diff --git a/TelegramExportProcessor.sln b/TelegramExportProcessor.sln index eeae638..ba966a2 100644 --- a/TelegramExportProcessor.sln +++ b/TelegramExportProcessor.sln @@ -18,6 +18,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Directory.Build.props = Directory.Build.props .github\workflows\dotnet-ci.yml = .github\workflows\dotnet-ci.yml README.md = README.md + sample.fsx = sample.fsx EndProjectSection EndProject Global diff --git a/sample.fsx b/sample.fsx new file mode 100644 index 0000000..94d7841 --- /dev/null +++ b/sample.fsx @@ -0,0 +1,28 @@ +#r "nuget: TelegramExportProcessor, 0.0.3" + +open System +open TelegramExportProcessor + +let args = fsi.CommandLineArgs + +let find_string (messages: ChatMessage seq) (searchString : string) = + messages |> Seq.filter (fun m -> m.TextEntities |> Seq.exists(fun te -> te.Text.Contains(searchString))) + +let print_messages (messages: string seq) = + for m in messages do + printfn "%s\n======================================" m + +let format_message (message : ChatMessage) = + let messageParts = message.TextEntities |> Seq.map (fun te -> te.Text) + ("", messageParts) |> System.String.Join + +let search_in_file file searhString = + let data = ExportParser.ParseChatExportFile file + let messages_with_string = find_string data.Messages searhString |> Seq.map format_message + print_messages messages_with_string + +match args with +| [| _ ; _ |] -> raise (Exception "Please specify search string") +| [| _ ; file; searchString |] -> search_in_file file searchString +| [| _; _ ; _ ; _|] -> raise (Exception "Too many parameters given") +| _ -> raise (Exception "No export file given")