Hey so im trying to get the current oil price and then do some math on it for a hw assignment. Im having trouble getting it to find the numbers i need on the website. here is my code
# Module oilcost.py to compute the delivery cost for home heating oil.
# Assume your delivery company charges a 10% fee on top of the price
# per gallon. The module should take one command line argument
# indicating the number of gallons needed and should output the
# total cost.
import sys
import re
import urllib
def getOilPrice(url):
f = urllib.urlopen(url)
html=f.read()
f.close()
match = re.search(r'<span class="dailyPrice">( d+.? d+)</span>', html)
return match.group(1) if match else '0'
def outputPrice(oilprice, gallons, total):
print 'The current oil price is $ %s' %oilprice
def main():
url = 'http://www.indexmundi.com/commodities/?commodity=heating-oil'
oilprice = float(getOilPrice(url)) # Create this method
gallons = float(sys.argv[1]) # Get from command line
total = (gallons * 1.1) * oilprice
outputPrice(oilprice, gallons, total) # Create this method
if __name__ == '__main__':
main()
can anyone let me know what im doing wrong?