Transcribed TextTranscribed Text

Fundamentals of Programming and Problem Solving Homework 5: RSS Reader In this project, we will make an RSS reader. RSS is a standardized format for publishing updates to web content. 1. Install software a. appJar appJar is a Python package for making simple graphical user interfaces (GUIs). The program, as well as documentation, to download appJar. Place the unzipped appJar directory in the same directory as the Project 2 code. b. Feedparser Feedparser is a Python package for downloading and parsing RSS feeds. Feedparser can be installed using the Python pip package manager. To install Feedparser, open the command prompt and type pip install feedparser. Documentation for Feedparser c. Test installation Open the Homework 5 code file in IDLE and run it. If it runs without errors, everything should be correctly installed. 2. Understanding the data structure In this problem, we will take a look at the data structures built by the feedparser package. There is nothing to turn in for this problem but understanding these objects is necessary for the completion of the rest of this assignment. 1 Given a url for an RSS feed url, the feedparser.parse(url) retrieves and parses the corresponding feed. We’ll take a look at the data structure returned by this function. a. In the Python shell, run import feedparser. Then run feed_dict = feedparser.parse('http://') The resulting object feed_obj is a dictionary. b. Next, run feed_dict.keys(). This will display the keys of this dictionary. We will look at a few of them. (1) First, run feed_dict['feed']. This object is itself a dictionary containing information about the feed. Try, for example, running feed_dict['feed']['title'] to get the feed’s title from this dictionary. (2) Second, run feed_dict['href']. This returns the link to this feed. (3) Third, run feed_dict['updated']. This returns the time at which the feed was updated. (4) The main value that we will need from this dictionary is feed_dict['entries']. Don’t run this directly in the IDLE shell. This object is large enough that IDLE may freeze when trying to print it. Instead, run type(feed_dict['entries']) to see that this object is a list. c. The feed_dict['entries'] object is a list containing the stories in the feed. Run story_dict = feed_dict['entries'][0] to get a dictionary containing information about the first story in the feed. We’ll now look at a few of the key-value pairs in story_dict. (1) The key 'title' gives the title of the story. Run story_dict['title'] to see this. (2) The key 'summary' gives a summary of the story. Run story_dict['summary'] to see this. (3) The key 'link' gives a summary of the story. Run story_dict['link'] to see this. 3. Choosing the feed Now we’ll begin work on our RSS reader. Look at the window that results from running the Homework 5 code. Notice that there is a dropdown menu at the top containing a list of RSS 2 feeds. Below this dropdown menu is an empty menu (a ListBox in appJar). The goal of this problem is to fill in the entries of this ListBox menu with entries corresponding to items in the feed selected in the dropdown menu. To do this, you will fill in the supplied feed_changed() function. This function is called by appJar whenever the selected feed is changed. You will need to follow these steps: a. Get the feed currently selected in the dropdown menu (specifically, an appJar OptionBox) using the command window.getOptionBox('feeds'). Use this to get the URL for the selected feed from the feed_dict dictionary. Then download and parse the feed using the feedparser.parse function. As described in Problem 2, this function will return a dictionary representing the contents of the feed. See the Feedparser documentation for more details. b. Next, you need to construct a list of the titles of the items in the feed. If you have named the feed dictionary current_feed, you can access the list of items for this feed using current_feed['entries']. For a given item current_item (also a dictionary) in this list, you can get its title using current_item['title']. Refer back to Problem 2 for more on these data structures. c. Once you have the list of titles, update the ListBox using window.updateListBox('items', title_list), where title_list is the list of titles of entries in the feed. See the appJar documentation for more information. 4. Choosing the item Look at the Summary and Link items in the appJar window. Next, we want to fill these in with the summary and link to the item selected in the ListBox (which should now be filled after completion of Problem 2). To do this, you will fill in the supplied entry_changed() function. a. Get the selected item title in the ListBox using window.getListBox('entries'). From there, you will need to get the item in current_feed['entries'] that has this title. b. Once you have this item, use item['summary'] to get its summary and item['link'] to get the link. 3 c. Note that the string returned by item['summary'] has html attached to the end. Remove this html. You may assume that the character < does not occur in the text of any summary and therefore be used to indicate where the html begins. The split method for strings might be useful here. This method breaks a string into pieces based on a delimiter string. For example, consider the string s = 'This-is-an-example.' We can break this string into pieces defined by the character '-' using the split method as follows: words = s.split('-') words ['This','is','an','example.'] d. Finally, you will need to update the appJar Message to display the summary using window.setMessage('summary', current_summary) and update the link using window.setLink('Link', current_link).

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

import feedparser
from appJar import gui

# Feed names and URLs
feed_dict = {'Reuters US News':'',
             'Reuters World News':'',
             'Reuters Arts News':'',
             'Reuters Business News':'',
             'Reuters Science News':'',
             'Reuters Environm...

By purchasing this solution you'll be able to access the following files: and

for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Python Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Upload a file
Continue without uploading

We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats