Created
May 20, 2021 13:02
-
-
Save cgarvis/808d72b8708afcfbf492f5ffe844e78f to your computer and use it in GitHub Desktop.
Download zip, extract, and parse csv in Elixir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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