|
@@ -1,6 +1,7 @@
|
|
|
defmodule Vaccins.LocationStore do
|
|
defmodule Vaccins.LocationStore do
|
|
|
defmodule Location do
|
|
defmodule Location do
|
|
|
alias __MODULE__, as: Location
|
|
alias __MODULE__, as: Location
|
|
|
|
|
+ @limit 60 * 60 * 24
|
|
|
|
|
|
|
|
defstruct [
|
|
defstruct [
|
|
|
:id,
|
|
:id,
|
|
@@ -23,8 +24,18 @@ defmodule Vaccins.LocationStore do
|
|
|
with url <- q |> provider.to_url() |> URI.to_string(),
|
|
with url <- q |> provider.to_url() |> URI.to_string(),
|
|
|
{:ok, result} <- url |> Vaccins.Scraper.get_json() do
|
|
{:ok, result} <- url |> Vaccins.Scraper.get_json() do
|
|
|
case result |> provider.analyze_result() do
|
|
case result |> provider.analyze_result() do
|
|
|
- {:ok, slots} -> {id, slots, bp}
|
|
|
|
|
- {:error, reason} when reason in [:no_availability] -> {id, reason}
|
|
|
|
|
|
|
+ {:ok, slots} ->
|
|
|
|
|
+ case slots
|
|
|
|
|
+ |> Enum.group_by(&(&1 |> DateTime.diff(DateTime.utc_now()) |> abs < @limit)) do
|
|
|
|
|
+ grouped = %{true: before_limit} ->
|
|
|
|
|
+ {:ok, before_limit, grouped |> Map.get(false, [])}
|
|
|
|
|
+
|
|
|
|
|
+ %{false: after_limit} ->
|
|
|
|
|
+ {:ok, after_limit}
|
|
|
|
|
+ end
|
|
|
|
|
+
|
|
|
|
|
+ error = {:error, reason} when reason in [:no_availability] ->
|
|
|
|
|
+ error
|
|
|
end
|
|
end
|
|
|
end
|
|
end
|
|
|
end
|
|
end
|