Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enumerating through Channel then Posts #1

Open
ghost opened this issue Apr 26, 2015 · 1 comment
Open

Enumerating through Channel then Posts #1

ghost opened this issue Apr 26, 2015 · 1 comment

Comments

@ghost
Copy link

ghost commented Apr 26, 2015

Apologies, Elixir noob trying to port something from C#.

Once we have our successfully interpreted RSS feed, how do we enumerate through each post adding the data to a map (title and url specifically, not that it makes much difference)

-Wil

@shymega
Copy link

shymega commented Jan 12, 2017

Hi there! Sorry to see the long wait you've had, and I hope this response isn't too late for you.

I'm working on a RSS aggregator in my free time, and I had this exact problem. Here's a example piece of code for you, which adds the title & link to a Map.

    HTTPoison.start()

    feed_url = "https://www.theguardian.com/uk/rss"
    
    {:ok, %HTTPoison.Response{body: body}} = HTTPoison.get(feed_url)
    {:ok, feed, _} = FeederEx.parse(body)

    IO.puts("Feed title: #{feed.title}")

    rss_map = Enum.map(feed.entries, fn (entry) -> %{:title => entry.title,
                                                 :link => entry.link} end)
    |> Enum.uniq()

    IO.inspect(rss_map)

This code will enumerate over the feed items returned from The Guardian (UK) newspaper, and return a Map in List form, which you can then enumerate over to retrieve each item, which should, fingers crossed, have a title and link key and respective value.

I hope this helps, Will.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant