Skip to content

Instantly share code, notes, and snippets.

@ourway
Created April 6, 2019 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ourway/123f1b94c4e700e02177c2ef7f4e159c to your computer and use it in GitHub Desktop.
Save ourway/123f1b94c4e700e02177c2ef7f4e159c to your computer and use it in GitHub Desktop.
File.stream!("priv/repo/data/MCI_SECRET_prepaid/postpaid_Table.csv")
|> CSV.decode()
|> Enum.take(1)
|> Enum.map(fn row ->
{:ok, [state, city, _, num]} = row
changeset =
Red9.MSID.changeset(
%Red9.MSID{},
%{
is_prepaid: false,
state:
case state do
"" ->
"FLAT"
state ->
state
end,
city:
case city do
"" ->
"FLAT"
city ->
city
end,
num: num
}
)
if changeset.valid? == true do
changeset |> Red9.Repo.insert()
end
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment