So
Dunkm1n asked in
this thread about a digg news feed reader for geektool.
I got bored and made one, here it is for everybody to use (all these readers are based off the same code, it's really trivial to get the info you need from Python).
Save the code as digg_news_grabber.py and chmod +x the file.
Code:
#!/usr/bin/env python
# MODULE IMPORTS
import xml.dom.minidom
import re
# CLASS TO HOLD THE DATA FOR A TO DO GROUP
class diggNewsItem():
def __init__(self):
self.title = ""
self.link = ""
self.desc = ""
self.pubdate = ""
self.dcount = ""
self.dcategory = ""
# GET THE FEED - UPDATE TO CMD LINE ARGUMENT
# BE SURE TO HAVE THE URL REDIRECT THE URL FROM THE COMMAND LINE WITH
# THE FOLLOWING COMMAND
# curl --silent "url goes here in quotations or else it won't work" > /tmp/digg_news_feed.xml
dom = xml.dom.minidom.parse("/tmp/digg_news_feed.xml")
# LIST TO HOLD ALL THE TASKS (toDo CLASS)
diggNews = []
# INLINE FUNCTIONS - DON'T FEEL LIKE CLASSING THIS UP
def getText(nodelist):
rc = []
for node in nodelist:
if node.nodeType == node.TEXT_NODE:
rc.append(node.data)
return ''.join(rc)
def handleFeed(feed,diggNews):
items = feed.getElementsByTagName("item")
handleNewsItem(items,diggNews)
def handleNewsItem(items,diggNews):
for item in items:
# CREATE TEMPORARY TODO
tmpCls = diggNewsItem()
# GET THE DATA FROM THE CURRENT ITEM
title = item.getElementsByTagName("title")[0]
link = item.getElementsByTagName("link")[0]
pubdate = item.getElementsByTagName("pubDate")[0]
desc = item.getElementsByTagName("description")[0]
dcount = item.getElementsByTagName("digg:diggCount")[0]
dcat = item.getElementsByTagName("digg:category")[0]
# GET THE VALUES FROM THE TAGS
tmpCls.title = getText(title.childNodes).strip()
tmpCls.link = getText(link.childNodes).strip()
tmpCls.desc = getText(desc.childNodes).strip()
tmpCls.pubdate = getText(pubdate.childNodes).strip()
tmpCls.dcount = getText(dcount.childNodes).strip()
tmpCls.dcategory = getText(dcat.childNodes).strip()
# APPEND TEMP DIGG NEWS CLASS TO DIGG NEWS LIST
diggNews.append(tmpCls)
# HANDLE THE XML
handleFeed(dom,diggNews)
# PRINT OUT THE TASKS
# THIS IS CUSTOMIZABLE
for i in range(len(diggNews)):
# PRINT OUT THE DATA HOWEVER YOU WANT
# DATA STORED IN EACH diggNews SEGMENT
# diggNews[i].title = TITLE OF THE NEWS ITEM
# diggNews[i].desc = DESCRIPTION OF THE NEWS ITEM
# diggNews[i].link = NEWS ITEM LINK
# diggNews[i].pubdate = DATE THE NEWS ITEM WAS PUBLISHED
# diggNews[i].dcount = NUMBER OF DIGG COUNTS
# diggNews[i].dcat = CATEGORY
# CURRENTLY SET TO PRINT THE DIGG COUNT AND THEN THE TITLE
print "(" + diggNews[i].dcount + ") " + diggNews[i].title
For Geektool, use the following commands. Dunkm1n wanted the top news, but if you have a digg account, you could probably pull one of your feeds through, just place it between the quotes in the curl statement.
Code:
curl --silent "http://services.digg.com/2.0/story.getTopNews?type=rss" > /tmp/digg_news_feed.xml;
python /path/to/your/script/digg_news_grabber.py
Output is customizable (available variables are detailed in the script), I pulled the important information from the XML. The default output is as follows:
Code:
(103) How Science Saved My Soul [Video]
(103) 8 Great Laptops With WiMAX 4G
(102) What Are Capital Gains? (Graphic)
(106) Pervert Paid Pack of 12y/o Girls Thousands of Dollars to Fulfill His Sexual Wish List
(115) In Case You Still Dont Understand What Happened November 2
(101) Facebook fan numbers accurately predict 81% of midterm election results
(116) It's time you wear brown ribons [Pic]
(134) Men Are So Under Appreciated (Pic)
(111) Exactly what kind of people watch Leno, Conan, and Letterman?
(102) The Top 8 Songs To Listen To While Punching Yourself in the Face
(108) Michael Douglas 7 Year-Old Daughter Takes Care Of Him, Makes Him Smoothies So Hell Gain Weight!
(105) Scientists Make Breakthrough in Invisibility Clothing, Stalkers Rejoice
(111) 10 Toys That Will Permanently Screw Up Your Kid
(126) Fiscal Responsibility And Runaway Military Spending Are Not Compatible
(182) Is Xbox Kinect Racist? Not Even Close (Screw You Gamespot)
(119) Startup Turns 10,000 Lbs of Landfill-Bound Coffee Grounds into Oyster Mushrooms
(120) People who swallow foreign objects: Medical treatment is costly
(107) First look at the new 'Tron' costumes (pics)
(130) Attempted Abduction of 11-Year-Old Girl a Hoax; Girl Made Up Story
(125) Shirtless Toolbag gets Tased at a Subway (Video)
(The output is the current news when I pulled the feed down with the curl redirect)