CS 1MD3 - Winter 2006 - Assignment #5
Generated for Student ID: 0568063
Due Date: April 5th, 2006
(You are responsible for verifying that your student number is
correct!)
NOTE: All submissions must be plain text format in ".py"
files.Instructions
Using the libraries sys, re, and urllib
, write a Python program to convert the value of a given amount of money from one currency to another. Your program will accept two 3-letter currency codes (the "from" currency, and the "to" currency) along with a floating-point value. It will acquire the conversion from www.oanda.com, extract the relevant text, and display it in the console. Here are some results which your program should reproduce (with current monetary values, of course):
$ python currency.py CAD USD 23.59
23.59 Canadian Dollar = 20.41788 US Dollar
$ python currency.py EUR JPY 84.24
84.24 Euro = 11,947.6 Japanese Yen
$ python currency_cmdline.py ISK GTQ 123.45
123.45 Iceland Krona = 13.66300 Guatemalan Quetzal
The URL: http://www.oanda.com/convert/classic
Notes:
- You may assume that the user has provided valid command-line arguments. No need to check that there are three of them, that the first two are valid currency codes, or that the third one is a floating-point number.
- You must mimic the output format exactly as shown above. This will mean discarding huge amounts of HTML to get at the relevant text.
- Although the web form at www.oanda.com contains several variables (
language, margin, lang,
etc.), it appears to require only an amount and the two currency codes. Use the variables value
, exch2
, and expr2
for this purpose.