Skip to content

Instantly share code, notes, and snippets.

@cgarvis
Created May 20, 2021 13:02
Show Gist options
  • Save cgarvis/808d72b8708afcfbf492f5ffe844e78f to your computer and use it in GitHub Desktop.
Save cgarvis/808d72b8708afcfbf492f5ffe844e78f to your computer and use it in GitHub Desktop.
Download zip, extract, and parse csv in Elixir
defmodule Website do
alias NimbleCSV.RFC4180, as: CSV
def fetch_data(url) do
with {:ok, resp} <- HTTPoison.get(report.url, [timeout: 50_000]),
{:ok, files} <- :zip.extract(resp.body),
{_name, content} <- hd(files),
rows <- CSV.parse_string(content)
do
{:ok, rows}
else
{:error, err} -> {:error, err}
err -> {:error, err}
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment