~ihabunek/triglav

af6a0a8c11333d17ca8575d34a1013085ccfa751 — Ivan Habunek 1 year, 2 months ago f82337d
Add pulapromet
M lib/triglav/public_transport.ex => lib/triglav/public_transport.ex +4 -0
@@ 15,6 15,7 @@ defmodule Triglav.PublicTransport do
  defdelegate import_gpp_osijek(opts \\ []), to: Triglav.PublicTransport.ImportGtfs
  defdelegate import_hzpp(opts \\ []), to: Triglav.PublicTransport.ImportGtfs
  defdelegate import_jadrolinija(opts \\ []), to: Triglav.PublicTransport.ImportGtfs
  defdelegate import_pulapromet(opts \\ []), to: Triglav.PublicTransport.ImportGtfs
  defdelegate import_zet(opts \\ []), to: Triglav.PublicTransport.ImportGtfs

  @doc """


@@ 64,6 65,8 @@ defmodule Triglav.PublicTransport do
         {:ok, {feed, true}} <- fun.(opts) do
      generate_mappings(feed.id)
      generate_errors(feed.id)
    else
      error -> Logger.error("Failed updating #{operator.name()}: #{inspect(error)}")
    end
  end



@@ 74,6 77,7 @@ defmodule Triglav.PublicTransport do
      "zet" -> {:ok, &import_zet/1}
      "gpp_osijek" -> {:ok, &import_gpp_osijek/1}
      "jadrolinija" -> {:ok, &import_jadrolinija/1}
      "pulapromet" -> {:ok, &import_pulapromet/1}
      _ -> {:error, :unknown_operator}
    end
  end

M lib/triglav/public_transport/import_gtfs.ex => lib/triglav/public_transport/import_gtfs.ex +8 -0
@@ 48,6 48,14 @@ defmodule Triglav.PublicTransport.ImportGtfs do
    import_from_archive(operator, target, opts)
  end

  def import_pulapromet(opts \\ []) do
    operator = Operators.pulapromet()
    url = "https://b2b.promet-info.hr/dc/b2b.gtfs.pulapromet"
    target = Triglav.tmp_dir!() <> "/#{operator.slug}.zip"
    Npt.download!(url, target)
    import_from_archive(operator, target, opts)
  end

  defp import_from_url(operator, url, opts) do
    target = Triglav.tmp_dir!()
    path = Http.download!(url, target, overwrite: true, filename: "#{operator.slug}.zip")

M lib/triglav/public_transport/operators.ex => lib/triglav/public_transport/operators.ex +9 -0
@@ 40,6 40,15 @@ defmodule Triglav.PublicTransport.Operators do
    })
  end

  def pulapromet() do
    get_or_insert!(%Operator{
      name: "Pulapromet",
      ref: "Pulapromet",
      slug: "pulapromet",
      wikidata_id: "Q12640747"
    })
  end

  def zet() do
    get_or_insert!(%Operator{
      name: "Zagrebački električni tramvaj",