Does SimplePie automatically remove invalid images and links? - hyperlink

I am working on a web application and want to use SimplePie for parsing a lot of RSS feeds.
One problem is that I want to know if SimplePie automatically removes all the dead links while parsing RSS feeds. So that the final output of the RSS feed doesn't have any invalid links.

No, it does not. In order to do so, you'd have to send a HEAD request for every link in the feed. This is too expensive for SimplePie to do, so you'll need to find code to do that on your own. Try this example on SO.

Related

How to scrape different URLs from database with Nokogiri with different requirements

I tried using Feedjira to assist with content analysis from newsfeeds, but it appears that RSS feeds now only link to content rather than including them with RSS as I found out in "Feedjira not adding content and author". I plan to use Feedjira to get the URL for the article, but then use Nokogiri to scrape the article and pick out the relevant parts.
The problem is that each media outlet will have a different format for their pages and I need to know the best way for Nokogiri to take the URL from the database (supplied by Feedjira) and depending on the associated feed title (also the database from Feedjira sync) scrape the page in a specific way and save it to a separate table in the database. Anyone got any suggestions?
I don't know your special use case but I'm also doing content analysis using news feeds.
Maybe you'll have a look on Readability which provides you a generic content scraper.
The problem you've encountered is that every feed generator does it a bit differently, just as with HTML generators. You can assume certain fields are going to be in place in an RDF, RSS or ATOM feed, however the author of the feed could use optional tags that you could find very useful, so you have to write code to look for them.
I wrote several feed aggregators in the past, including one that was handling well over 1000 feeds daily. By sniffing out the feed type, ATOM vs. RSS vs RDF, then I could make sensible checks for fields that were interesting given that format, and extract the data if it was available.
Pre-canned parsers get it wrong too often, either grabbing data you don't want and making a mess of the output, or skipping data you do want leaving gaps in the output, so be prepared to write code if you want it done correctly.
You'll probably want to take advantage of a backing database too, to keep track of what you looked at last and when you're supposed to look at it again; That's part of being a good network citizen. You'll also want to keep track whether a feed was down the last n times you looked so you can trim out dead sites.

How to display different feed data (using feedzirra)

So, I'm using feedzirra gem (https://github.com/pauldix/feedzirra) for parsing and displaying RSS data. However, I'm having trouble displaying different feeds. The code in my view is displaying FeedEntry.all, albeit, I'd like to display several different feeds under different headers.
I'm having trouble wrapping my head around how to do this. Another way of putting it would be, how can you seperate the feeds? Anyway to seperate them by title and display them by the title?
E.G if I were to pull data from YouTube's rss (hypothetically), and Spotify's as well how could I display YouTube's rss under the YouTube header, and likewise with Spotify?
Here's the gist of it: https://gist.github.com/anonymous/5801535
Have you looked at backending your feedzirra output with a tool like data_active to convert it into an ActiveRecord structure? I am just beginning to build a similar process so I don't yet have code to show. I recognize there are some duplications here so it may be that feedzirra does the fetch and data_active does the parse.

How to parse RSS with Code Igniter?

I want to parse this RSS (from a bit.ly user stream) to grab all bit.ly links and related data, and store all new items into a database. What are examples of easy ways to parse RSS (e.g. simple helpers with small footprint)? I'm a Code Igniter rookie, so please be gentle :)
I ended up by simply using json_decode(file_get_contents('http://bitly.com/u/joaoramos.json')); and then dug into the object to get what I needed.
Check out SimplePie. Integrating this in CI , shouldn't be hard .
Or If you want one with less foot print, check this Thread on CI forums , This is very light and does the job.

RSS feeds in new twitter

Does anyone know where to find the RSS feeds in the new twitter? I cannot find the rss icon and the source of the page just points to "Your Twitter Favorites" even though I am on the page of the user I want to get an RSS feed from...
Simple I know, but its bugging me to no end!
2014 edit:
It looks like Twitter has retired RSS feeds, and now only exports data as JSON:
What output formats will API v1.1 support?
API v1.1 will support JSON only. We’ve been hinting at this for some
time now, first dropping XML support on the Streaming API and more
recently on the trends API. XML, Atom, and RSS are infrequently used
today, and we’ve chosen to throw our support behind the JSON format
shared across the platform. Consequently, we’ve decided to discontinue
support for these other formats. For historical context, when we
originally built the API all major languages did not have performant,
well vetted libraries supporting JSON - today they do.
Orignal 2010 answer:
Here are the various feed URLs (using the account "Twitter" for these examples):
http://twitter.com/statuses/public_timeline.rss
http://twitter.com/statuses/user_timeline/Twitter.rss
http://twitter.com/favorites/Twitter.rss
http://search.twitter.com/search.rss?q=Twitter
The new Twitter layout isn't very RSS-friendly, unfortunately.
You won't be able to find it because Twitter stopped support for RSS :(
Something I needed, so built a Twitter to RSS converter, it works on hashtags, searches and lists. I've now opened it up totally free for anyone else who needs a solution.
Get it here - Twitter RSS Feed Generator
Recommende you to use the free website ahejlsberg, put the id into the textbox next to #, then click the "Fetch RSS" button.
You can get the RSS feed url: https://twitrss.me/twitter_user_to_rss/?user=ahejlsberg.
I found that this works for particular users (I had been trying to figure out their ids which was the way rss used to work but this works fine):
[Updated]
http://api.twitter.com/1/statuses/user_timeline.rss?screen_name=johnpiper
[Updated Sept 2014]
no longer works again...
[Alternative Solution: May 2015]
I have since discovered http://www.queryfeed.net
http://www.queryfeed.net/twitter?q=from%3Ajohnpiper
See the home page for further documentation about how to structure other queries. The service does not seem to return all tweets.

Ruby Rss parser and event trigger

I'm using RSS library so i can parse Atom and RSS in Ruby and Rails and store it in a model.
I've looked at the standard RSS library, but is there one library that will auto-detect that there is a new rss feed so i can update my database ?
what are the best practice to trigger an instruction in order to store the new rss feed ?
should i use threads to handle that problem ?is it going to be slow?
thank you for your help
OK heres the deal.
If you want a real fast feed parser go for Feedzirra. Does not work on windows. http://github.com/pauldix/feedzirra
Autodiscovery?
-Theres truffle-hog if you don't want to do GET redirects. http://github.com/pauldix/truffle-hog
-Theres feedbag if you want to do GET redirects to find feeds from given urls. This is slower though. http://github.com/damog/feedbag
Feedzirra is the best bet if you want to poll for new entries for your feed. But if you want a more non-polling solution to your problem then i would suggest going through the pubsubhubbub spec. Make sure while parsing your feeds they are pubsubhubbub enabled. Check for the link tag. If it points to pubsubhubbub.appspot.com or any other pubsub enabled hub then just subscribe to the feed by sending a subscription request to the hub. You can then define a endpoint in your app which will in turn receive updated entry pings for your feed subscription from the hub. Just read the raw POST data and store it in your database. Stats are that 95% of the blogger blogs are pubsub enabled. That is a lot of data in your hands already. :)
If you are polling for changes then you should check the last-modified or etag from the header rather than parse the entire feed again. Saves you from wasting resources. Feedzirra takes care of this for you.
I am not sure what you mean by "auto-detect" a new feed?
Are you looking for code that can discover when someone creates a new feed on a site? Or, do you mean discover when an existing feed has a new article?
The first is tough because your code needs to know what site to look at so it needs some sort of auto-discovery of sites with new feeds. Searching the google for "new rss feeds" doesn't return anything that looks useful, at least not on the first page. If you, or your users, know of a new site then you can have an interface to add new sites to search. Then you grab the page at that URL, look for the RSS/Atom auto-discovery links, and go from there. Auto-discovery links can open a can of worms because of duplicate content being served using different protocols (RDF, RSS and Atom), so you have to determine which to use, or multiple feeds with alternate content listed.
If you mean you want to discover when an existing feed has new articles, then you have to keep track of the last time your code looked at the feed, and the last article that was seen, then retrieve the feed and see if any articles were not in your list of previously seen articles. Your code needs to be sensitive to the time-to-live information in a lot of feeds too. Hitting the feed every fifteen minutes when they update once a week is bad form. Most aggregation code can do those things already but you might need to configure a database and tell the code how to find it.
Generally, for this sort of task I set up a crontab entry on a production Linux or Unix system and fire off the job periodically, looking in the database for feeds whose last-run-time plus the stored time-to-live value is in the past.
Does that help any?
Very easy solution is to use Dynamic attribute-based finders
When you are filling your model with RSS feed data, instead of Model.create(...) use Model.find_or_create_by_column(value, :other_column => other_value).
You can specify a date as unique value or RSS message title ... (whatever you want)
I think this is pretty easy. You can make some cron task to fill your model once per hour for example. Only new feeds will be added.
There is no chance to get some "event" when RSS is updated without downloading whole RSS feed again.

Resources