O'Reilly Forums: Twitter Problems - O'Reilly Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Twitter Problems

#1 User is offline   Susan Halgašová 

  • New Member
  • Pip
  • Group: Members
  • Posts: 1
  • Joined: 02-May 14

Posted 02 May 2014 - 11:10 AM

Hi, i have a problem with the chapter 3, to be more specific, with the twitter code...
I used the send_to_twiiter() code you have got on your website but it shows me an error, maybe there is a problem with my code, the get_price function
but i had been working b4 the twitter thing... Can you help me?

here is the error:

Traceback (most recent call last):
File "C:/Python33/functions.py", line 26, in <module>
send_to_twitter(get_price())
TypeError: send_to_twitter() takes 0 positional arguments but 1 was given

here is my code:

import urllib.request
import time

def send_to_twitter():
msg = "I am a message that will be sent to Twitter"
password_manager = urllib.request.HTTPPasswordMgr()
password_manager.add_password("Twitter API","http://twitter.com/statuses", "zuzhal", "sakrakurva22")
http_handler = urllib.request.HTTPBasicAuthHandler(password_manager)
page_opener = urllib.request.build_opener(http_handler)
urllib.request.install_opener(page_opener)
params = urllib.parse.urlencode( {'status': msg} )
resp = urllib.request.urlopen("http://twitter.com/statuses/update.json", params)
resp.read()

def get_price():
page=urllib.request.urlopen("http://beans.itcarlow.ie/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" or "Y":
send_to_twitter(get_price())

else:
price=99.99
while price>4.74:
time.sleep(60)
price=get_price()
send_to_twitter("buy")
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users