Analyzing the Program
In this step, you will analyze the Python program on a line-by-line basis.
Ensure that Line Numbers are enabled in Komodo (View|View Line Numbers).
Ensure that the file "xmlrpcdemo.py" is displayed in the Komodo Editor.
About Meerkat
Meerkat
is a Web-based syndicated content reader created by O'Reilly.
It is based on Rich Site Summary (RSS), an XML specification used for distributing news,
product announcements, discussion threads, and other assorted content as channels. Meerkat
provides a simple interface for these stories. |
Lines 1 to 3 - Import Module
- imports the "xmlrpclib" module (installed in
Adding Modules using the PyPPM)
- creates the "server" object, based on the Server class from the "xmlrpclib" module
- the Server class uses the oreillynet.com URL as an argument and connects to the specified URL
Komodo Tip on line 2, type:
server = xmlrpclib.
When you type the period, Komodo displays a list of the methods and properties
contained in the module "xmlrpclib". This is
AutoComplete. |
Lines 5 to 7 - Create Lists
- creates the "categories" list object, which stores data collected by the "getCategories" method
- initializes the "interestingCategories" list object, which is left empty, as indicated by the "[]"
Komodo Tip notice that syntax elements are
displayed in different colors. You can adjust the display options for language elements
in the Preferences dialog box. |
Top
Lines 9 to 13 - Determine "interestingCategories"
- in the "for" loop, each category object in the "categories" list is evaluated by the "if" statement
on line 12
- the "if" statement converts the category title to lowercase, then looks for occurrences of the
text "python"
- when the "if" statement finds a match, it appends the category to the "interestingCategories" list
Lines 15 to 16 - Print the HTML Header
- the beginning of the HTML output is printed to the Output tab
Top
Lines 21 to 23 - Format Category Headings
- a second "for" loop starts here, as the "interestingCategories" list is now examined
- "%s" is a placeholder for a string, which is defined after the closing quote of the print string
- the "title" component of the current item in the category list is substituted in the output for "%s"
Komodo Tip click on the
minus symbol to the left of line 21. The entire section of nested code
will be collapsed. This is
Code
Folding. |
Lines 24 to 27 - Article Selection Criteria
- a dictionary named "params" is created, which contains the criteria for article selection
- because this sub-routine is repeated for each category in the "interestingCategories"
list, it is specifically designed to search only the current category
- the "time_period" parameter selects articles within the specified time frame
Python Pointer good Python code is
liberally annotated with comments (indicated by the "#" symbol) |
Top
Lines 29 to 35 - Create Article Links
- the "articles" list object is created from the information gathered by the "getItems" method,
which uses "params" as its argument
- in the "for" loop, the print statement uses string placeholders to pass the URL and title to the
output
- the final line prints the closing HTML tags as output
Komodo Tip click the mouse pointer on the closing
parenthesis on line 29. Notice that its color changes to a bold red. The opening brace is displayed the same way. |
Python Pointer notice that there are two
"format specifiers" ("%" symbols) and two specifications ("article['link']" and "article['title']") on line
33. They will be matched in sequence, so that the first specification replaces the first specifer
and the second specification replaces the second specifier. |
|