Skip to content

Commit

Permalink
Update core to 0.16
Browse files Browse the repository at this point in the history
  • Loading branch information
pNre committed Dec 29, 2023
1 parent bc6c819 commit 366cddb
Show file tree
Hide file tree
Showing 12 changed files with 68 additions and 54 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ jobs:
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- uses: docker/setup-buildx-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
Expand Down
28 changes: 14 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
FROM ocaml/opam:ubuntu-22.04-ocaml-4.14 AS base
RUN opam update
RUN opam depext async.v0.15.0 async_ssl.v0.15.0 camlimages caqti.1.9.0 caqti-driver-sqlite3.1.9.0 cohttp tls
RUN opam depext async.v0.16.0 async_ssl.v0.16.0 camlimages caqti.1.9.0 caqti-driver-sqlite3.1.9.0 cohttp tls
RUN opam install -y 'base64'
RUN opam install -y base.v0.15.0
RUN opam install -y ppx_bench.v0.15.0 ppx_expect.v0.15.0 variantslib.v0.15.0 sexplib.v0.15.0
RUN opam install -y ppx_jane.v0.15.0
RUN opam install -y core.v0.15.0
RUN opam install -y async.v0.15.0
RUN opam install -y async_ssl.v0.15.0
RUN opam install -y re2.v0.15.0
RUN opam install -y textutils.v0.15.0
RUN opam install -y core_extended.v0.15.0
RUN opam install -y base.v0.16.3
RUN opam install -y ppx_bench.v0.16.0 ppx_expect.v0.16.0 variantslib.v0.16.0 sexplib.v0.16.0
RUN opam install -y ppx_jane.v0.16.0
RUN opam install -y core.v0.16.0
RUN opam install -y async.v0.16.0
RUN opam install -y async_ssl.v0.16.1
RUN opam install -y re2.v0.16.0
RUN opam install -y textutils.v0.16.0
RUN opam install -y core_extended.v0.16.0
RUN opam install -y tls
RUN opam install -y ssl
RUN opam install -y cohttp-async.5.2.0
RUN opam install -y cohttp-async.5.3.0
RUN opam install -y caqti.1.9.0
RUN opam install -y caqti-driver-sqlite3.1.9.0
RUN opam install -y caqti-async.1.9.0
RUN opam install -y xmlm jsonaf.v0.15.0 ppx_jsonaf_conv.v0.15.0
RUN opam install -y xmlm jsonaf.v0.16.0 ppx_jsonaf_conv.v0.16.0
RUN opam install -y ppx_deriving
RUN sudo apt-get install -y libjpeg-dev libpng-dev
RUN opam install -y camlimages
RUN opam install -y bignum.v0.15.0
RUN opam install -y camlimages.5.0.4
RUN opam install -y bignum.v0.16.0
RUN sudo apt-get update
RUN sudo apt-get install -y libopencv-dev

Expand Down
12 changes: 11 additions & 1 deletion hera/module_air_quality/module_air_quality.ml
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
open Async
open Core
open Error_handler
open Jsonaf.Export

type city = { name : string } [@@deriving of_jsonaf] [@@jsonaf.allow_extra_fields]

type time =
{ iso : string
; s : string
}
[@@deriving of_jsonaf] [@@jsonaf.allow_extra_fields]

type data =
{ city : city
; dominentpol : string
; aqi : int
; time : time
}
[@@deriving of_jsonaf] [@@jsonaf.allow_extra_fields]

Expand Down Expand Up @@ -51,13 +59,15 @@ let handle_success chat_id body =
| Ok { status = _; data } ->
let main = data.dominentpol in
let aqi = data.aqi in
let ts = data.time.s in
let text =
sprintf
"Air quality in %s\nAQI: *%d*, *%s*\nMain pollutant: *%s*"
"Air quality in %s\nAQI: *%d*, *%s*\nMain pollutant: *%s*\nUpdated on %s"
data.city.name
aqi
(string_of_aqi aqi)
(description_of_concern main)
ts
in
Telegram.send_message_don't_wait ~chat_id ~text ()
| Error err -> handle_module_error chat_id (`Exn err)
Expand Down
1 change: 1 addition & 0 deletions hera/module_dictionary/module_dictionary.ml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
open Async
open Core
open Jsonaf.Export

type domain = { text : string } [@@deriving of_jsonaf] [@@jsonaf.allow_extra_fields]

Expand Down
50 changes: 25 additions & 25 deletions hera/module_faces/module_faces.ml
Original file line number Diff line number Diff line change
Expand Up @@ -101,21 +101,21 @@ let download_and_process_photo file_id =
let cropped_face_zoomed = cropped face_zoomed in
Result.return
((if !quality < default_quality
then
[ rgb24 image
; scale_image cropped_face_small scaled_width
; scale_image cropped_face_large scaled_width
; scale_image cropped_face_zoomed scaled_width
]
else
[ scale_image cropped_face_small scaled_width
; scale_image cropped_face_large scaled_width
; scale_image cropped_face_zoomed scaled_width
])
|> List.map ~f:(fun image ->
let name = photo ^ (Image_id.create () |> Image_id.to_string) in
image#save name (Some Jpeg) [ Save_Quality !quality ];
name))
then
[ rgb24 image
; scale_image cropped_face_small scaled_width
; scale_image cropped_face_large scaled_width
; scale_image cropped_face_zoomed scaled_width
]
else
[ scale_image cropped_face_small scaled_width
; scale_image cropped_face_large scaled_width
; scale_image cropped_face_zoomed scaled_width
])
|> List.map ~f:(fun image ->
let name = photo ^ (Image_id.create () |> Image_id.to_string) in
image#save name (Some Jpeg) [ Save_Quality !quality ];
name))
| Some (_, landmarks) ->
Logging.Module.info "Face found, %i landmarks" (List.length landmarks);
Result.fail (`Err "Failed to process image")
Expand All @@ -141,9 +141,9 @@ let compress_photos chat_id photos =
match content with
| Ok photos ->
photos
|> Deferred.List.iteri ~f:(fun index photo ->
let filename = sprintf "fc_%i.jpg" index in
Telegram.send_photo ~chat_id ~photo ~filename ~mimetype:"image/jpg" >>| ignore)
|> Deferred.List.iteri ~how:`Parallel ~f:(fun index photo ->
let filename = sprintf "fc_%i.jpg" index in
Telegram.send_photo ~chat_id ~photo ~filename ~mimetype:"image/jpg" >>| ignore)
| _ -> Deferred.unit
in
let compare_photos a b =
Expand All @@ -166,13 +166,13 @@ let on_update update =
| `Command ("fc", args, chat_id, _) ->
is_waiting_for_image := true;
quality
:= args
|> List.last
|> Option.map ~f:Caml.String.trim
|> Option.map ~f:int_of_string_opt
|> Option.join
|> Option.map ~f:(fun quality -> min 100 (max 1 quality))
|> Option.value ~default:default_quality;
:= args
|> List.last
|> Option.map ~f:Stdlib.String.trim
|> Option.map ~f:int_of_string_opt
|> Option.join
|> Option.map ~f:(fun quality -> min 100 (max 1 quality))
|> Option.value ~default:default_quality;
Telegram.send_message_don't_wait ~chat_id ~text:"Send me a picture" ();
true
| `Photos (photos, chat_id, _) when !is_waiting_for_image ->
Expand Down
4 changes: 2 additions & 2 deletions hera/module_feeds/feed.ml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ let map_date mapping date = match date with Date date -> mapping date | _ -> Non
let map_atom_link ~xmlbase entry =
match entry with
| Link (attributes, _) ->
Some (Caml.List.assoc "href" attributes |> resolve_uri ~xmlbase)
Some (Stdlib.List.assoc "href" attributes |> resolve_uri ~xmlbase)
| _ -> None
;;

Expand Down Expand Up @@ -119,7 +119,7 @@ let parse_feed xmlbase input =
;;

let parse ~xmlbase content =
let content = Caml.String.trim content in
let content = Stdlib.String.trim content in
let input = Xmlm.make_input (`String (0, content)) in
try Ok (parse_feed xmlbase input) with Xmlm.Error (_, error) ->
Error (`Parse ((0, 0), sprintf "Couldn't parse feed, %s" (Xmlm.error_message error)))
Expand Down
8 changes: 4 additions & 4 deletions hera/module_feeds/feed_date.ml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ let of_rfc822 string =
| Some (_, x) -> x
| _ -> string
in
let components = date |> Caml.String.trim |> String.split ~on:' ' in
let components = date |> Stdlib.String.trim |> String.split ~on:' ' in
let parse () =
match components with
| [ day; month; year; time ] ->
Expand All @@ -66,9 +66,9 @@ let of_rfc822 string =
| _ ->
let time =
string
|> Time_unix.of_string
|> Time.to_span_since_epoch
|> Time.Span.to_sec
|> Time_float_unix.of_string
|> Time_float.to_span_since_epoch
|> Time_float.Span.to_sec
|> Ptime.of_float_s
in
if Option.is_none time then Logging.Module.error "Invalid date %s" string;
Expand Down
2 changes: 1 addition & 1 deletion hera/module_feeds/subscription.ml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ let begin_checking_subscription subscription send =
let key = Subscription.key subscription in
let cancellation = Ivar.create () in
Hashtbl.set subscription_tasks ~key ~data:cancellation;
let timespan = Time.Span.create ~min:5 () in
let timespan = Time_float.Span.create ~min:5 () in
Clock.every'
~stop:(Ivar.read cancellation)
~continue_on_error:true
Expand Down
1 change: 1 addition & 0 deletions hera/module_markets/markets.ml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
open Async
open Core
open Jsonaf.Export

(* Types *)

Expand Down
6 changes: 3 additions & 3 deletions hera/module_markets/position.ml
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ let start_checking position send =
to_string_hum ~delimiter:'.' ~decimals:4 change ^ "%")
in
let market_time time =
Time_unix.(
Time_float_unix.(
let time =
time.Markets.raw
|> Int63.of_int64_trunc
|> Span.of_int63_seconds
|> Time.of_span_since_epoch
|> Time_float.of_span_since_epoch
in
let zone = Zone.find_exn "Europe/Rome" in
let formatted_zone = Zone.abbreviation zone time in
Expand Down Expand Up @@ -73,7 +73,7 @@ let start_checking position send =
in
let cancellation = Ivar.create () in
Hashtbl.set position_tasks ~key:position.pos.id ~data:cancellation;
let timespan = Time.Span.create ~min:10 () in
let timespan = Time_float.Span.create ~min:10 () in
Clock.every'
~stop:(Ivar.read cancellation)
~continue_on_error:true
Expand Down
2 changes: 1 addition & 1 deletion hera/module_morejpeg/module_morejpeg.ml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ let on_update update =
quality
:= args
|> List.last
|> Option.map ~f:Caml.String.trim
|> Option.map ~f:Stdlib.String.trim
|> Option.map ~f:int_of_string_opt
|> Option.join
|> Option.map ~f:(fun quality -> min 100 (max 1 quality))
Expand Down
5 changes: 3 additions & 2 deletions hera/telegram/telegram.ml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
open Async
open Core
open Poly
open Jsonaf.Export

type user =
{ id : int64
Expand Down Expand Up @@ -320,8 +321,8 @@ let parse_update update =
| { message = Some { chat = { id = chat_id; _ }; text = Some t; _ }; _ } ->
(match String.split t ~on:' ' with
| command :: args ->
let command = command |> Caml.String.trim |> String.lowercase in
let args = args |> List.map ~f:Caml.String.trim in
let command = command |> Stdlib.String.trim |> String.lowercase in
let args = args |> List.map ~f:Stdlib.String.trim in
`Command (command, args, chat_id, update)
| _ -> `Unknown)
| { message = Some { chat = { id = chat_id; _ }; photo = photos; _ }; _ }
Expand Down

0 comments on commit 366cddb

Please sign in to comment.