def main_thread(master): # A sample trigger list - you'll replace # this with something more configurable in Problem 11 try: # These will probably generate a few hits... t1 = TitleTrigger("nemtsov") t2 = TitleTrigger("Spanish") t3 = PhraseTrigger("Election") t4 = OrTrigger(t2, t3) triggerlist = [t1, t4] # TODO: Problem 11 # After implementing makeTrigger, uncomment the line below: # triggerlist = readTriggerConfig("triggers.txt") # **** from here down is about drawing **** frame = Frame(master) frame.pack(side=BOTTOM) scrollbar = Scrollbar(master) scrollbar.pack(side=RIGHT,fill=Y) t = "Google & Yahoo Top News" title = StringVar() title.set(t) ttl = Label(master, textvariable=title, font=("Helvetica", 18)) ttl.pack(side=TOP) cont = Text(master, font=("Helvetica",14), yscrollcommand=scrollbar.set) cont.pack(side=BOTTOM) cont.tag_config("title", justify='center') button = Button(frame, text="Exit", command=root.destroy) button.pack(side=BOTTOM) # Gather stories guidShown = [] def get_cont(newstory): if newstory.getGuid() not in guidShown: cont.insert(END, newstory.getTitle()+"\n", "title") cont.insert(END, "\n---------------------------------------------------------------\n", "title") cont.insert(END, newstory.getSummary()) cont.insert(END, "\n*********************************************************************\n", "title") guidShown.append(newstory.getGuid()) def whileloop(): print "Polling . . .", # Get stories from Google's Top Stories RSS news feed stories = process("http://news.google.com/?output=rss") # Get stories from Yahoo's Top Stories RSS news feed stories.extend(process("http://rss.news.yahoo.com/rss/topstories")) # Process the stories stories = filterStories(stories, triggerlist) map(get_cont, stories) scrollbar.config(command=cont.yview) print "Sleeping..." frame.after(60000, whileloop) except Exception as e: print e whileloop() if __name__ == '__main__': root = Tk() root.title("Some RSS parser") main_thread(root) root.mainloop()
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question