The Tasks This Python Program Must Do
[p] As the engine of the application, this program will need to perform
the following tasks:
[ul]
[li] Receive user input (the name of the feed) [/li]
[li] Retrieve the location of the feed (from the data file) [/li]
[li] Retrieve the feed (from a web server) [/li]
[li] Retrieve the some but not all pieces of information from the feed
(the headlines and links) [/li]
[li] Format the data for web publishing [/li]
[li] Return the data to the PHP script for printing to the web page [/li]
[/ul]
[/p]
[p]
For it to fulfill these duties, the Python program will need to borrow
code from a few libraries. We will need the following:
[ul]
[li] [b] string [/b]: to parse the data retrieved from the data file [/li]
[li] [b] sys [/b]: to parse the user input [if CGI is used instead of
PHP, then we need [b] cgi [/b] and [b] cgitb [/b], remembering to call
cgitb.enable( if you feel a bit lost with this, see my
tutorials on Python with PHP and Python CGI, respectively] [/li]
[li] [b] urllib2 [/b]: this module is used for opening URLs and
reading from them; we will obviously use it to retrieve the feed [/li]
[li] [b] xml.dom [/b]: all RSS feeds come in XML format (it is the RSS
standard), and we must be ready to parse it; for our purposes, we
will be using a particular part of [b] xml.dom [/b] called [b]
minidom [/b] (you will learn more about this later) [/li]
[/ul]
[/p]
[p]
So with that understanding, put these import declarations at the
beginning of your program:
[blockquote shade=yes]
import string [br]
import sys [br]
import urllib2 [br]
from xml.dom import minidom [br]
[/blockquote]
[/p]
[p]
If you are unsure about the reason for importing modules and how to do
it, you should read [link url=/od/tutorial1/ss/pytutsyntax_9.htm] my
discussion on importing modules [/link] from the Python Library. If
you would like to know more about frequently used modules in the
Python Library or are unsure of what it is, see [link
url=http://python.about.com/od/pythonstandardlibrary/a/pylibrary.htm] my page on the
subject [/link].[/p]
_z_800_z_._z_/z/js/abb.txt_z_python_z__z_1_z_2093_z_1);
- This is NOT the Beginning
- Python Best Practice: the Bang Line
- The Tasks This Python Program Must Do
- Holding the User Data in Python With CGI
- Holding the User Data in Python With PHP
- Defining the First Python Function
- Reading the RSS Feed as a Python File Object
- Using a Python Iterator
- Calling Python's Function, Retrieving the Feed Address

