Hello all,
I’m playing with nhs API, and after fetching the data and doing some clean up I’m a bit stuck on how to remove items from the list.
I’m doing everything from the iex
shell so the code goes something like this
nhs_endpoint = "https://api.nhs.uk/conditions/pregnancy-and-baby/"
headers = [{"subscription-key", "key"}]
%{status_code: 200, body: body, request_url: request_url} = HTTPoison.get!(nhs_endpoint, headers)
%{"url" => url, "author" => author, "dateModified" => date_created, "description" => title, "mainEntityOfPage" => page, "relatedLink" => link} = Poison.decode!(body)
# Go trough the map of map and map URL into list
l = Enum.flat_map(link, fn %{"relatedLink" => relatedLink} -> relatedLink end)
Enum.flat_map(l, fn %{"relatedLink" => relatedLink} -> relatedLink |> Enum.map(fn %{"url" => url} -> url end) end)
It will basically boil don’t to this list of URLs
["https://api.nhs.uk/conditions/coronavirus-covid-19-old2/people-at-higher-risk-from-coronavirus/pregnancy-and-coronavirus/",
"https://api.nhs.uk/conditions/pregnancy-and-baby/due-date-calculator/",
"https://api.nhs.uk/conditions/pregnancy-and-baby/when-pregnancy-goes-wrong/",
"https://www.nhs.uk/start4life/signups/new",
"https://api.nhs.uk/conditions/pregnancy-and-baby/healthy-pregnancy-diet/",
"https://api.nhs.uk/conditions/pregnancy-and-baby/planning-pregnancy/",
"https://api.nhs.uk/conditions/pregnancy-and-baby/foods-to-avoid-pregnant/",
...]
this is a shorter version of the result, but as you see I have an imposter starting with https://www.nhs.uk/*
which I want to remove, so what is a proper way of removing these items?