Bläddra i källkod

Store locations in a file via DETS

theenglishway (time) 4 år sedan
förälder
incheckning
30b4c7f28c
5 ändrade filer med 22 tillägg och 44 borttagningar
  1. BIN
      Elixir.Vaccins.LocationStore
  2. 3 0
      lib/vaccins/application.ex
  3. 16 43
      lib/vaccins/location_store.ex
  4. 2 1
      mix.exs
  5. 1 0
      mix.lock

BIN
Elixir.Vaccins.LocationStore


+ 3 - 0
lib/vaccins/application.ex

@@ -16,6 +16,9 @@ defmodule Vaccins.Application do
       {Finch, name: Vaccins.Finch}
     ]
 
+    # This should not be done here but whatever..
+    {:ok, _} = :dets.open_file(Vaccins.LocationStore, type: :set)
+
     # See https://hexdocs.pm/elixir/Supervisor.html
     # for other strategies and supported options
     opts = [strategy: :one_for_one, name: Vaccins.Supervisor]

+ 16 - 43
lib/vaccins/location_store.ex

@@ -30,49 +30,22 @@ defmodule Vaccins.LocationStore do
     end
   end
 
+  require Ex2ms
   alias Vaccins.Queries.Doctolib
+  @name Vaccins.LocationStore
 
-  def get_locations(),
-    do:
-      [
-        %Location{
-          name: "Centre de Vaccination - Salle Olympe de Gouges",
-          provider: Doctolib,
-          availability_query_params: [
-            visit_motive_ids: 2_549_915,
-            agenda_ids:
-              "434477-434486-434466-434472-440075-440077-440078-415625-434490-462178-462452-433984-462177-433604-433601-415628-440074-433997-434489-440076",
-            practice_ids: 164_922,
-            limit: 7
-          ],
-          booking_page:
-            "https://partners.doctolib.fr/centre-de-sante/fontenay-sous-bois/centre-de-vaccination-covid-19-fontenay-sous-bois?pid=practice-180541"
-        },
-        %Location{
-          name: "Centre de Vaccination - Paris 20e",
-          provider: Doctolib,
-          availability_query_params: [
-            visit_motive_ids: 2_549_915,
-            agenda_ids:
-              "463167-415613-463168-415615-429620-434343-463166-463170-463171-447048-440655-434052-440654-462614-462613-433994-434337-434338",
-            practice_ids: 166_459,
-            limit: 3
-          ],
-          booking_page:
-            "https://www.doctolib.fr/centre-de-sante/paris/centre-de-vaccination-covid-19-ville-de-paris?pid=practice-166459"
-        },
-        %Location{
-          name: "Hotel de ville de Fontenay-sous-Bois",
-          provider: Doctolib,
-          availability_query_params: [
-            visit_motive_ids: 2_743_304,
-            agenda_ids: "449169-449170-466472",
-            practice_ids: 180_541,
-            limit: 15
-          ],
-          booking_page:
-            "https://partners.doctolib.fr/centre-de-sante/fontenay-sous-bois/centre-de-vaccination-covid-19-fontenay-sous-bois?pid=practice-180541&enable_cookies_consent=1"
-        }
-      ]
-      |> Enum.map(&(&1 |> Location.set_id() |> Location.build_query()))
+  def get_locations() do
+    select_all =
+      Ex2ms.fun do
+        x -> x
+      end
+
+    :dets.select(@name, select_all) |> Enum.map(fn {_k, v} -> v end)
+  end
+
+  def insert_all(locations) do
+    locations |> Enum.each(&:dets.insert(@name, {&1.id, &1}))
+  end
+
+  def build_location(l = %Location{}), do: l |> Location.set_id() |> Location.build_query()
 end

+ 2 - 1
mix.exs

@@ -44,7 +44,8 @@ defmodule Vaccins.MixProject do
       {:jason, "~> 1.0"},
       {:plug_cowboy, "~> 2.0"},
       {:floki, "~> 0.30.0"},
-      {:finch, "~> 0.6"}
+      {:finch, "~> 0.6"},
+      {:ex2ms, "~> 1.0"}
     ]
   end
 

Filskillnaden har hållts tillbaka eftersom den är för stor
+ 1 - 0
mix.lock