# Creates a RSS Newspaper from digg only! # Requirements: # Python v 2.4.2 <-- Well it was made with that so i assume that is should be a requirement #Amara(http://uche.ogbuji.net/uche.ogbuji.net/tech/4suite/amara/) #HTMLgen (http://starship.python.net/crew/friedrich/HTMLgen/html/main.html) #A web browser to view output #What its going to do: # Parse and take the Title and Descriptions from www.digg.com (which is a open post new feed bascailly) # Parse and take weather info # Generate a table on the html page "Digg_Feed.htm" # Input all data into the table # Save it and make readble # No Arguments #---Importing Modules import htmllib import httplib import urllib import os import amara import HTMLgen as htm import time #---Defining dumb line functions def line(): print "__________________________________________________" def line2(): print "==================================================" class Digg: pass print "Digg Imported" def __init__(self): # Amara importing self.rssDigg = amara.parse("http://www.digg.com/rss/index.xml") # Get the title and description # First TOPIC self.d1_title = self.rssDigg.rss.channel.item[0].title self.d1_data = self.rssDigg.rss.channel.item[0].description # Second TOPIC self.d2_title = self.rssDigg.rss.channel.item[1].title self.d2_data = self.rssDigg.rss.channel.item[1].description # Third Topic self.d3_title = self.rssDigg.rss.channel.item[2].title self.d3_data = self.rssDigg.rss.channel.item[2].description # Fourth Topic self.d4_title = self.rssDigg.rss.channel.item[3].title self.d4_data = self.rssDigg.rss.channel.item[3].description # Firth Topic self.d5_title = self.rssDigg.rss.channel.item[4].title self.d5_data = self.rssDigg.rss.channel.item[4].description # Convert the nodes to string values # First Node self.d1 = str(self.d1_title) self.d11 = str(self.d1_data) # Second Node self.d2 = str(self.d2_title) self.d22 = str(self.d2_data) # Third Node self.d3 = str(self.d3_title) self.d33 = str(self.d3_data) # Forth Node self.d4 = str(self.d4_title) self.d44 = str(self.d4_data) # Fifth Node self.d5 = str(self.d5_title) self.d55 = str(self.d5_data) def feed2text(self): # Write all the titles and descriptions to a file. woo = open("Digg_Feed_Text.txt", "w") woo.write("TOP FIVE TOPICS FOR DIGG ARE: " "\n") woo.write(" " "\n") woo.write("================================" "\n") woo.write(self.d1) woo.write("\n") woo.write("___________+" "\n") woo.write(self.d11 + "\n") woo.write("\n") woo.write("\n") woo.write("++++++++++++++++++++++++++++++++" "\n") woo.write(self.d2) woo.write("\n") woo.write("___________+" "\n") woo.write(self.d22) woo.write("\n") woo.write("\n") woo.write("+++++++++++++++++++++++++++++++ " "\n") woo.write(self.d3) woo.write("\n") woo.write("___________+" "\n") woo.write(self.d33) woo.write("\n") woo.write("\n") woo.write("+++++++++++++++++++++++++++++++ " "\n") woo.write(self.d4) woo.write("\n") woo.write("___________+" "\n") woo.write(self.d44) woo.write("\n") woo.write("\n") woo.write("+++++++++++++++++++++++++++++++ " "\n") woo.write(self.d5) woo.write("\n") woo.write("___________+" "\n") woo.write(self.d55) woo.write("\n") woo.write("\n") woo.write("+++++++++++++++++++++++++++++++ " "\n") # Close the file woo.close # Make file readable woo = open("Digg_Feed_Text.txt", "r") print "Go to your text file called, 'Digg_Feed.txt'. Your text is in there" class Weather: pass def __init__(self): print "Weather is imported" self.rssw = amara.parse("http://www.rssweather.com/wx/us/ga/roswell/rss.php?config=&forecast=zandh&place=roswell&state=ga&zipcode=&country=us&county=13121&zone=gaz033&alt=rss20a") self.rwTitle = self.rssw.rss.channel.title self.rw1Cat = self.rssw.rss.channel.item[0].category self.rw1Title = self.rssw.rss.channel.item[0].title self.rw1Date = self.rssw.rss.channel.item[0].pubDate self.rw1Temp =self. rssw.rss.channel.item[0].description self.rssw = amara.parse("http://www.rssweather.com/wx/us/ga/roswell/rss.php?config=&forecast=zandh&place=roswell&state=ga&zipcode=&country=us&county=13121&zone=gaz033&alt=rss20a") self.rw1Cat = self.rssw.rss.channel.item[1].category self.rw2Title = self.rssw.rss.channel.item[1].title self.rw2Descrp = self.rssw.rss.channel.item[1].description self.rwstr1title = str(self.rw1Title) #---Prints Currents weathers stats in console or interperter def printCurrent(self): print self.rwTitle line2() print "Date:", self.rw1Date print "Category:", self.rw1Cat print "Title :: ", self.rw1Title line() print "Description:", self.rw1Temp #---Prints 2 Nights weathers stats in console or interperter def print2Night(self): print self.rwTitle line2() print "Date:", self.rw2Date print "Category:", self.rw2Cat print "Title :: ", self.rw2Title line() print "Description:", self.rw2Temp #---Binding func weatherCurrent() to weather.printCurrent() def weatherCurrent(): W = Weather() Weather.printC = W.printCurrent Weather.printC() #---Binding func weather2night() to the weather.print2Night() def weather2Night(): W = Weather() Weather.printT = W.print2Night Weather.printT() class Wired: pass #--- Never got around to creating some for wired :-( #TODO:!Get around to making a feed for Wired! class SlashDot: pass #---Never got around to creating some for slashdot :-( #TODO:!!Get around to making a feed for Slashdot! def feed2html(): #---Convert feed 2 HTML S = htm.Strong() d = htm.Table("RSSNewspaper") h = ["The Top 5 Stories on Digg are:", "Weather"] d.heading = h Sd1 = str(loo.d1) Sd2 = str(loo.d2) Sd3 = str(loo.d3) Sd4 = str(loo.d4) Sd5 = str(loo.d5) FirstT = [S(Sd1)] FirstD = [loo.d11] SecondT = [S(Sd2)] SecondD = [loo.d22] ThirdT = [S(Sd3)] ThirdD = [loo.d33] ForthT = [S(Sd4)] ForthD = [loo.d44] FifthT = [S(Sd5)] FifthD = [loo.d55] #New data curwstr = str("Current Weather: ") currentWE = [S(curwstr)] westrTitle = str(hoo.rw1Title) westr2date = str(hoo.rw1Date) westr2cat = str(hoo.rw1Cat) westr2temp = str(hoo.rw1Temp) # New Column WeatherW2title = [S("Title: ") + "\n\t" + westrTitle] WeatherW2date = [S("Date: ") + "\n\t" + westr2date] WeatherW2cat = [S("Catergory: ") + "\n\t" + westr2cat] WeatherW2temp = [S("Temperature: ") + "\n\t" + westr2temp] #---Create empty cells Empty = str(" ") EmptyC = [Empty] #---Define some rows for the table Row1 = FirstT + currentWE Row2 = FirstD + EmptyC Row3 = SecondT + WeatherW2title Row4 = SecondD + WeatherW2date Row5 = ThirdT + WeatherW2cat Row6 = ThirdD + WeatherW2temp Row7 = ForthT + EmptyC Row8 = ForthD + EmptyC Row9 = FifthT + EmptyC Row10 = FifthD + EmptyC #---Apply rows to the table d.body = [Row1, Row2, Row3, Row4, Row5, Row6, Row7, Row8, Row9, Row10] k = str(d) woo2html = open("Digg_Feed.htm", "w") woo2html.write(k) woo2html.close woo2html = open("Digg_Feed.htm", "r") #---autoexec.bat.python :-) hoo = Weather() loo = Digg() feed2html() loo.feed2text() # Program Done # print "DONE"