Monday, February 13, 2012

Python Tkinter and Feedparser.py Cleaned Up a Little.

So, after some massaging of the available information and examples, I now have a list (not necessarily a python list) of items in the feed. Instead of printing them, I'm going to insert them into the form.


At first, I was going to use a text box. While that is functional, I see the need, in the future, to be able to select a feed item for download. So, for now I'm going to use a listbox. I'll add this to the GUI file and reference it as listbox1 in the program.

Some of the big changes: The button no longer has a function associated with it. I moved the she-bang line  (#! /usr/bin/env python) from  the GUI file to the program as it should have been from the start.

listing of generic3.py:

import sys
from Tkinter import *
   
class Application(Frame):

        def __init__(self,master=None):
                Frame.__init__(self, master)
                self.pack()
                self.createWidgets()

        def createWidgets(self):

            self.frame0 = Frame(self)
            self.frame0.pack()
           
            self.label1 = Label(self.frame0, text="This is a text label.")
            self.label1.grid( row=0, column=0)

            self.listbox1 = Listbox(self.frame0,width=60)
            self.listbox1.grid (row=2,column =0, columnspan =3)

            self.button1 = Button(self.frame0, text = "Push Button")
            self.button1.grid(row=1,column=0)

            self.button2 = Button(self.frame0, text = "Quit",command=self.quit)
            self.button2.grid(row=1,column=1)


And the listing for l-gen3.py

#! /usr/bin/env python

from generic3 import *
import urllib2, sys, feedparser

app=Application()
app.master.title("Hello There")
app.master.geometry("600x400+20+20")

#GLOBALS
url1="http://feeds.feedburner.com/antiwar-radio"

def feedinfo(url, output=sys.stdout):

    feed_data = feedparser.parse(url)
    channel, items = feed_data.feed, feed_data.entries


    print("Feed Title: ",channel['title'])

    for item in items:
        print( "Title: ",item['title'])
        app.listbox1.insert(END, item['title'])

    return

def process(self):
     pass
     print ("process activated")
     print (url1)
     feedinfo(url1)
     print (data)

feedinfo(url1)
#app.button1.bind("<Button-1>", process)

app.mainloop()

Next step, I guess, is to select one of the feeds in the list and download it.

No comments:

Post a Comment