XML technologies / XML / Python & XML / The Python Internet APIs / Connecting websites

(Excerpt from "Python & XML" by Christopher A. Jones & Fred L. Drake, Jr.)

Let us return to 1999. A visionary beverage wholesaler sees the value of letting supermarkets order cases online, replacing received faxes and manual order entry. The company envisages supermarket buyers entering their current needs in a browser and placing orders through its online system.

Meanwhile, supermarkets increasingly automate inventory. Rather than have staff review stock and sales to predict demand, they install sophisticated point-of-sale software that performs these calculations. Once a week, it prints purchasing requirements based on consumption patterns, and the buyer submits orders as needed.

Further improvements

Now return to the present. You are asked to feed the supermarket’s automatically generated stock and sales forecasts into the wholesaler’s ordering system without human intervention. Ideally, supermarket computers should order automatically when stocks are low and demand requires it.

You must know how to query the supermarket’s forecasting system automatically and submit the results as an order. Ideally, both systems are web-enabled. Python and its Internet APIs then let you replace labor-intensive browser operations with scripts and logic.

Python to the rescue

We now explore Python’s Internet capabilities: building programs that act as browsers or web servers and retrieve URLs using protocols including FTP and HTTP.

Python’s Internet support includes modules for URLs (Universal Resource Locators). The urllib module constructs and parses URLs or retrieves them at runtime. Python also provides an HTTP module for easy programmatic access. If a particular stock price fascinates you and a website provides real-time quotes, a Python application can query it periodically, extract the quote, and display it on your desktop instead of making you open a browser every few hours.

Although this section surveys technologies for creative Internet solutions, starting with the basics is wise. The most fundamental Internet building block is the URL.

  

 

 

 

back to top