~ihabunek/triglav

ref: 5d2bb2e407c2fd29aeb1d54ada20a42a718380a3 triglav/lib/mix/tasks/triglav/import_gtfs.ex -rw-r--r-- 834 bytes
5d2bb2e4Ivan Habunek Fix directory structure to match module names 1 year, 4 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
defmodule Mix.Tasks.Triglav.ImportGtfs do
  use Mix.Task

  alias Triglav.Repo

  @shortdoc "Imports GTFS data for ZET routes"

  @impl Mix.Task
  def run(_args) do
    {:ok, _} = Application.ensure_all_started(:triglav)

    db_state = Triglav.DataImport.load_state()
    web_state = get_web_state()
  end

  defp get_web_state() do
    html = get("https://www.zet.hr/odredbe/datoteke-u-gtfs-formatu/669")
    Regex.run(~r/https:\/\/www.zet.hr\/UserDocsImages\/[^"]+/, html)
    |> IO.inspect(label: "matches")
  end

  defp get(url) do
    {:ok, {{'HTTP/1.1', 200, 'OK'}, _headers, body}} =
      :httpc.request(:get, {to_charlist(url), []}, [], [])

    to_string(body)
  end

  defp download(url, target) do
    {:ok, :saved_to_file} =
      :httpc.request(:get, {to_charlist(url), []}, [], stream: to_charlist(target))
  end
end