summaryrefslogtreecommitdiff
path: root/lib/plugins/boursorama.ex
diff options
context:
space:
mode:
Diffstat (limited to 'lib/plugins/boursorama.ex')
-rw-r--r--lib/plugins/boursorama.ex37
1 files changed, 22 insertions, 15 deletions
diff --git a/lib/plugins/boursorama.ex b/lib/plugins/boursorama.ex
index 025a250..5b1ea9a 100644
--- a/lib/plugins/boursorama.ex
+++ b/lib/plugins/boursorama.ex
@@ -1,5 +1,4 @@
defmodule Nola.Plugins.Boursorama do
-
def irc_doc() do
"""
# bourses
@@ -25,25 +24,34 @@ defmodule Nola.Plugins.Boursorama do
{:ok, nil}
end
- def handle_info({:irc, :trigger, cac, m = %Nola.Message{trigger: %Nola.Trigger{type: :bang}}}, state) when cac in ["cac40", "caca40"] do
+ def handle_info(
+ {:irc, :trigger, cac, m = %Nola.Message{trigger: %Nola.Trigger{type: :bang}}},
+ state
+ )
+ when cac in ["cac40", "caca40"] do
case HTTPoison.get(@cac40_url, [], []) do
{:ok, %HTTPoison.Response{status_code: 200, body: body}} ->
- html = Floki.parse(body)
+ {:ok, html} = Floki.parse_document(body)
board = Floki.find(body, "div.c-tradingboard")
cac40 = Floki.find(board, ".c-tradingboard__main > .c-tradingboard__infos")
instrument = Floki.find(cac40, ".c-instrument")
- last = Floki.find(instrument, "span[data-ist-last]")
- |> Floki.text()
- |> String.replace(" ", "")
- variation = Floki.find(instrument, "span[data-ist-variation]")
- |> Floki.text()
-
- sign = case variation do
- "-"<>_ -> "▼"
- "+" -> "▲"
- _ -> ""
- end
+
+ last =
+ Floki.find(instrument, "span[data-ist-last]")
+ |> Floki.text()
+ |> String.replace(" ", "")
+
+ variation =
+ Floki.find(instrument, "span[data-ist-variation]")
+ |> Floki.text()
+
+ sign =
+ case variation do
+ "-" <> _ -> "▼"
+ "+" -> "▲"
+ _ -> ""
+ end
m.replyfun.("caca40: #{sign} #{variation} #{last}")
@@ -54,5 +62,4 @@ defmodule Nola.Plugins.Boursorama do
m.replyfun.("caca40: erreur http")
end
end
-
end