burrodiarachidi

This commit is contained in:
Benedetta 2024-04-23 09:35:10 +02:00
parent f8933d8c07
commit 2b80b7e751
6 changed files with 38 additions and 43 deletions

View file

@ -1,26 +0,0 @@
type client_id = | MqClient | HttpClient
module MatrixRoom = struct
type t = string
let make str = str
end
type reminder = { (* from an issue in forgejo get a reminder *)
url: string;
title: string;
due_date: string option;
body: string;
matrix_target: MatrixRoom.t
}
type Riot.Message.t +=
| RegisterClient of (client_id * Riot.Pid.t)
| LookupClient of client_id
| ListIssues
| ForgejoIssues of reminder list
| ForgejoError of string
| InternalFailure of string
let forgejo_issues lst = ForgejoIssues lst
let forgejo_error reason = ForgejoError reason

View file

@ -1,7 +1,7 @@
(executable
(public_name pam)
(name main)
(libraries riot amqp-client-lwt pyml yojson batteries otoml syslog ptime)
(libraries pam riot amqp-client-lwt pyml yojson batteries otoml syslog ptime)
(preprocess
(pps lwt_ppx ppx_string ))
)

View file

@ -4,6 +4,7 @@ open Batteries
open Yojson.Safe
open Config
open Utils
open Pam
let issue_of_json (m_room: Datatypes.MatrixRoom.t) (json): Datatypes.reminder =
let open Yojson.Safe.Util in

View file

@ -1,26 +1,14 @@
open Datatypes
open Pam.Datatypes
open Batteries
open Utils
let _MQ_CLIENT = "mq_client"
let _HTTP_CLIENT = "http_client"
let generate_alert = function
(*
* if the deadline has passed: alert every day at noon
* else parse the alert
**)
| {due_date=None; _} -> None
| {due_date=Some date; body; _} ->
let now = Ptime_clock.now () in
let today = now |> Ptime.to_date in
Ptime.of_rfc3339 date
|> Ptime.rfc3339_string_error
|> Result.map (fun (timestamp, _, _) -> Ptime.to_date timestamp = today)
|> Option.some
let http_client (repos: Config.repo_data list) =
let http_actor = Httpclient.init repos in
let _ = print_endline "Initialized http client" in
@ -30,8 +18,8 @@ let http_client (repos: Config.repo_data list) =
match Riot.receive () with
| ListIssues ->
Httpclient.make_get_request http_actor
|> Result.map Datatypes.forgejo_issues
|> Result.map_error Datatypes.forgejo_error
|> Result.map Pam.Datatypes.forgejo_issues
|> Result.map_error Pam.Datatypes.forgejo_error
|> Result.fold ~ok:identity ~error:identity
|> Riot.send_by_name ~name:_MQ_CLIENT

View file

@ -1,2 +1,3 @@
(test
(name test_pam))
(name test_pam)
(libraries pam))

View file

@ -0,0 +1,31 @@
open Pam.Datatypes
let test1 () =
let body = {|@alert: -12:38 10:02 +09:24
## Description
Specify a time format by writing the exact time of the alert, then adding zero or more '+' or '-'.
Examples, due date is 1/1/1970:
1. 12:38: you get the alert 1/1/1970 at 12:38
2. -12:38: you get the alert 31/12/1969 at 12:38
3. --12:38: you get the alert 30/12/1969 at 12:38
4. +12:38: you get the alert 2/1/1970 at 12:38 |}
in
let _a = ("https://salsa.lezzo.org/api/v1/repos/bparodi/Documenti/issues/25", "Casa", ("2024-04-20T23:59:59+02:00"), body) in
let m = MatrixRoom.make "test" in
let reminder = {url="example.org"; title= "example"; due_date= Some "2024-04-20T23:59:59+02:00"; body=body; matrix_target=m} in
let res = Pam.Issue_parser.to_datetime reminder in
match res with
| Ok None -> failwith "none"
| Error e -> failwith e
| Ok (Some ar) ->
let _ = ar
|> List.map (fun n -> n |> Pam.Issue_parser.to_exact_date |> Option.get |> Ptime.to_rfc3339)|> List.iter print_endline in
failwith "MAnca +2 offset"
let () =
let _ = test1 ()
in ()