Skip to content

Commit

Permalink
Add sample in F#
Browse files Browse the repository at this point in the history
  • Loading branch information
kant2002 committed Nov 18, 2024
1 parent bd8bb6f commit fedf524
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions TelegramExportProcessor.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 28 additions & 0 deletions sample.fsx
Original file line number Diff line number Diff line change
@@ -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")

0 comments on commit fedf524

Please sign in to comment.