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.
Copyright © 2002 O'Reilly Verlag GmbH & Co. KG
You may print the online version for your private use.
Otherwise, this chapter from the book "Python & XML" is subject to the same conditions as the printed edition: the work and all its parts are protected by copyright. All rights reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
O’Reilly Verlag GmbH & Co. KG, Balthasarstraße 81, 50670 Köln, kommentar(at)oreilly.de