HOWTO: Use a Yahoo Pipe to filter feeds

One of my friends at work asked me today how I sift through volumes of news to find articles and information on Google and specifically on Google Code for my articles. The answer is simple, I don't. Granted, I DO read a LOT, but there just aren't enough hours in the day to read everything I want to. So, I have a Yahoo Pipe sift through the feeds for me. Pipes is "a powerful composition tool to aggregate, manipulate, and mashup content from around the web." Its fairly easy to use and doesn't require any code or coding experience, although understanding the basic layout of an RSS or Atom feed is a definite plus. The method I'm going to describe could work for any blogger or anyone who wants to filter a single or large group of feeds by keyword. I'm not going to go into the details of Yahoo Pipes, there are plenty of tutorials and examples for that. I'm just going to describe how I built the small pipe I use to filter for Google news.

The first step is to log into or create a Yahoo account and go to http://pipes.yahoo.com/pipes/ and click on Create Pipe. The first node we're going to use is under sources and is called "Fetch Feed". Add as many of these as you want to pull in all the feeds you will need.

Then use unions (located under Operators) to join these Fetches together. If you have more then 5 feeds, you will need multiple unions.

Finally, add a filter, also located under Operators. Here, "Permit" items that match "any" of the following. Then, add rules where item.description > Contains and then the word or phrase you want to search for. This filter will allow any posts that have the words through, and block everything else. Send the output of the Filter to the Pipe Output and you are done.

You can then subscribe to the output of this pipe with the reader of your choice. When I subscribe to my pipe's [feed](http://pipes.yahoo.com/pipes/pipe .run?_id=vF35LapU3BG9UzFodbq02Q&_render=rss) in Google Reader, I only see posts that contain the word Google or google. I also could have done that as one filter with a regular expression, or just with "oogle".

Here is a full view of the pipe

HOWTO: YUI Tabview

A few days ago I added the Digg counts to the bottom of the Posts page on gPowered.net. Although, the more posts that I add, the further down on the page this section will get, so I decided to play around with YUI's tabview control and put the post list in one tab, and the diggs in another. It turned out to be really easy:

First we need a few dependencies

    <!-- Dependencies -->  
    <!-- core CSS -->  
    <link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/2.3.0/build/tabview/assets/tabview.css">   

    <!-- optional skin for border tabs -->  
    <link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/2.3.0/build/tabview/assets/border_tabs.css">   

    <script type="text/javascript" src="http://yui.yahooapis.com/2.3.0/build/yahoo-dom-event/yahoo-dom-event.js"></script>  
    <script type="text/javascript" src="http://yui.yahooapis.com/2.3.0/build/element/element-beta-min.js"></script>  

    <!-- Source file -->  
    <script type="text/javascript" src="http://yui.yahooapis.com/2.3.0/build/tabview/tabview-min.js"></script>  

And then we just need to organize some DIVs

HTML <div id="demo" class="yui-navset"> <ul class="yui-nav"> <li class="selected"><a href="#posts"><em>Posts</em></a></li> <li><a href="#diggs"><em>Diggs</em></a></li> <li><a href="#HOWTOs"><em>HOWTO's</em></a></li> </ul> <div class="yui-content"> <div id="posts" style="margin: 10px"> <h3>Posts</h3> content </div> <div id="diggs" style="margin: 10px"> <h3>Diggs</h3> content </div> </div> </div>HTML

HOWTO: Pulling Google Bookmarks with Python

I love using Google Bookmarks (usually with the Google Toolbar) because it lets me get to my bookmarks at home on my laptop or desktop, at work, or anywhere. It's great. Now I'm using those bookmarks to power the links section of gPowered.net
First we're going to need the httplib2 library so we can authenticate against Google and grab the bookmark feed and then the ElementTree to help process the rss feed.

import httplib2
from elementtree import ElementTree

Then we'll setup the link to pull the rss from, authenticate against the request, and pull back the feed

login = "timothy.broder@gmail.com"  
password = "*****"
url = 'https://www.google.com/bookmarks/?output=rss&num;=1000'  

h = httplib2.Http()  
h.add_credentials(login, password)  

resp, content = h.request(url, "POST", body="nt", headers={'content-type':'text/plain'} )

I figured for this a hashmap (or dictionary) would work well using the tags on the bookmarks as keys, pointing to lists of bookmarks. Then when we display them, just iterate through the keys. I also kept a list of the keys to make sorting faster later on. So we define our objects and then loop through the rss object pulling out the tags for keys, the names of the links, and the urls. I define a small Bookmark class which holds a name and url which will go into the hashmap to make storing the bookmark's easier. When I try to add a bookmark to the dict's list I try to append it, if the key(tag) doesn't exist I know I have to start a new list.

class Bookmark:
 def __init__(self, name, link):
  self.name = name
  self.link = link

d = dict()
sort_keys = []
for item in tree.findall('item'):
 key = item.findtext('{http://www.google.com/searchhistory}bkmk_label')
 if (key != None) and (key != 'gpowered') and (key != 'BP') and (key != 'Quick Searches') and (key != 'Me'):
  title = item.findtext('title')
  link = item.findtext('link')
  try:
   d[key].append(Bookmark(title.encode('utf-8'), link))
  except KeyError:
   d[key] = [Bookmark(title.encode('utf-8'), link)]
   sort_keys.append(key)

Then we'll sort the key list and the list of each key. To do this we need a small function that defines how to sort a bookmark

def bookmark_compare(a, b):
 return cmp(a.name, b.name)

sort_keys.sort() 
for key in sort_keys:
 d[key].sort(bookmark_compare)

Check out the static HTML version Here. I also made a fancier version using YUI's TreeView