Connecting Web Sites

Let’s take a trip back to 1999. An imaginary beverage distributor sees value in allowing supermarkets to order beverage cases online. They hope this will replace the process of accepting a fax and manually keying in order details. The beverage company envisions a situation in which purchasing agents at the supermarkets could use their web browsers to quickly key in current needs and submit orders to the beverage company’s system.

At this same time, the supermarkets are getting more and more interested in automating their inventory control. Instead of having people pour over stock statistics and sales numbers as they attempt to forecast demand, companies are installing sophisticated point-of-sale software at registers that perform these calculations for them. Once a week the system spits out printouts of the purchasers’ needs based on buying patterns. The purchasing agent is then supposed to send out purchase orders as needed.

Continuing Improvement

Now let’s go into the present. You are asked to take the information that is being automatically generated by the supermarket’s inventory and sales forecasting system and plug it into the beverage company’s order system without the involvement of a human. Ideally, this process should allow for supermarket computers to automatically send out purchase orders to suppliers when stock is low and demand dictates.

In order to perform this new task, you need to know how to interrogate the supermarket’s inventory and forecasting system automatically, as well as how to submit the data you come up with as a purchase order to the beverage company. The ideal scenario, of course, is that both systems are web-enabled first. In this scenario, Python and its Internet APIs come to the rescue, allowing you to easily replace human-intensive browser operations with script and logic.

Python to the Rescue

We will now dive into Python’s support for the Internet, as well as explore how to construct programs that mimic browsers or act like web servers, fetching URLs of all types, including FTP and HTTP.

Python’s Internet support includes modules for working with URLs (Universal Resource Locators). Using the urllib module, you can build and deconstruct actual URLs, as well as retrieve them at runtime in your Python programs. Python also features an HTTP module that makes programmatic access to the HTTP protocol a breeze. For example, if there is specific stock price you are rabid about, and you know of a web site that retrieves live stock quotes, you can write a Python application to query that site for you periodically. Your program can extract the target stock quote and display it on your desktop instead of bringing up your browser every few hours to fetch the information from a specific site.

While this chapter presents a good view of the technologies needed to creatively develop Internet solutions, it’s wise to start with the basics. The most fundamental building block of the Internet is the URL.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
52.14.240.252