Posted 06 September 2011 - 05:22 AM
import urllib.request
import urllib.parse
import time
import sys
import tweepy
def send_to_twitter(msg):
CONSUMER_KEY = 'rbD5n7Jh1JpO1Uszo359Hw'
CONSUMER_SECRET = 'uPyAc00jWUrBgKNClNjQVTnb8K58JR8HMC669T0r8A8'
ACCESS_KEY = '335977233-L0EHAIfesIbSwnVZy5TFhJS6w1mBzAjypj3a9AiY'
ACCESS_SECRET = 'ul3WvKoha2w92Rh1Hcvf00iOTSWdNYXrLb0clP9361M'
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
api = tweepy.API(auth)
api.update_status(msg)
def get_price():
page = urllib.request.urlopen("http://www.beans-r-us.biz/prices.html")
text = page.read().decode("utf8")
where = text.find('>$')
start_of_price = where + 2
end_of_price = start_of_price + 4
return float(text[start_of_price:end_of_price])
price_now = input("Do you want to see the price now (Y/N)? ")
if price_now == "Y":
send_to_twitter(get_price())
else:
price = 99.99
while price > 4.74:
time.sleep(900)
send_to_twitter("Buy!")
I am getting this error Please help me out...
Do you want to see the price now (Y/N)? Y
Traceback (most recent call last):
File "C:\Documents and Settings\Admin\Desktop\Progs\Python\starbuzz009.py", line 31, in <module>
send_to_twitter(get_price())
File "C:\Documents and Settings\Admin\Desktop\Progs\Python\starbuzz009.py", line 19, in get_price
page = urllib.request.urlopen("http://www.beans-r-us.biz/prices.html")
File "C:\Python32\lib\urllib\request.py", line 138, in urlopen
return opener.open(url, data, timeout)
File "C:\Python32\lib\urllib\request.py", line 375, in open
response = meth(req, response)
File "C:\Python32\lib\urllib\request.py", line 487, in http_response
'http', request, response, code, msg, hdrs)
File "C:\Python32\lib\urllib\request.py", line 407, in error
result = self._call_chain(*args)
File "C:\Python32\lib\urllib\request.py", line 347, in _call_chain
result = func(*args)
File "C:\Python32\lib\urllib\request.py", line 560, in http_error_302
headers, fp)
urllib.error.HTTPError: HTTP Error 302: Found - Redirection to url '/WaddY/prices.html' is not allowed
Thanks.....
I am a begginer.. Any one to help