O'Reilly Forums: Sending Messages To Twitter - O'Reilly Forums

Jump to content

  • 3 Pages +
  • 1
  • 2
  • 3
  • You cannot start a new topic
  • You cannot reply to this topic

Sending Messages To Twitter

#21 User is offline   Nilfur 

  • New Member
  • Pip
  • Group: Members
  • Posts: 1
  • Joined: 25-October 10

Posted 25 October 2010 - 08:31 AM

Thankyou arcticrobot for your detailed answer. It worked on my Windows Computer.

Since I am using Python 3, just as most of the people that read the "Head First" book, I had to change JMiller's code. I used the 2to3.py script to do so. It comes with Python 3 and is located at \Python31\Tools\Scripts.

If you do not want to do this yourself, here is the JMiller's sourceodoe for step 3:
CODE

import tweepy

CONSUMER_KEY = 'paste your Consumer Key here'
CONSUMER_SECRET = 'paste your Consumer Secret here'

auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth_url = auth.get_authorization_url()
print('Please authorize: ' + auth_url)
verifier = input('PIN: ').strip()
auth.get_access_token(verifier)
print("ACCESS_KEY = '%s'" % auth.access_token.key)
print("ACCESS_SECRET = '%s'" % auth.access_token.secret)


0

#22 User is offline   winnarz 

  • New Member
  • Pip
  • Group: Members
  • Posts: 1
  • Joined: 07-November 10

Posted 07 November 2010 - 04:02 PM

Hi there. Thanks for the helpful posts guys. Also trying to add Tweepy but I use a mac. Complete beginner. Any advice on how I can add it to an Apple system?

Thanks!
0

#23 User is offline   Patrick Burdine 

  • New Member
  • Pip
  • Group: Members
  • Posts: 1
  • Joined: 08-November 10

Posted 08 November 2010 - 12:54 PM

Curses! I am getting this message -

CODE

Traceback (most recent call last):
File "setup.py", line 3, in <module>
from setuptools import setup, find_packages
ImportError: No module named setuptools


Any help? Also, I am tempted to just go with 2.7 rather than 3.1 for learning this. Thoughts on that?

Thanks!
0

#24 User is offline   Minas 

  • New Member
  • Pip
  • Group: Members
  • Posts: 1
  • Joined: 15-November 10
  • Gender:Male
  • Location:Nijkerk, The Netherlands

  Posted 15 November 2010 - 12:35 PM

Hello everyone,

I Just sucessfully posted a twitter message with the practice program on my windows 7 laptop. I folowed the instructions from arcticrobot, Nilfur and David Griffiths_1283427796.

Great Job everyone.

This forum is the ideal solution for this kind of things.

This post has been edited by Minas: 15 November 2010 - 12:56 PM

0

#25 User is offline   gonagi 

  • New Member
  • Pip
  • Group: Members
  • Posts: 3
  • Joined: 30-November 10

Posted 30 November 2010 - 08:28 PM

Hi,

I'm using Python 3.1.3 on Windows 7 32-bit.

When I installed tweepy 1.4-py3 and tried to authenticate the app,
I have got an error saying:

File "C:\Python31\lib\site-packages\tweepy-1.4-py3.1.egg\tweepy\auth.py", line 85, in get_authorization_url
raise TweepError(e)
tweepy.error.TweepError: HTTP Error 401: Unauthorized
-----
Do you have any idea about what I did wrong?
Could you tell me which version of Python and tweepy you are using?

Thanks in advance~~

QUOTE (Dananjaya86 @ Sep 29 2010, 06:50 AM) <{POST_SNAPBACK}>
Well I successfully posted bean prices to Twitter in Windows...If you're looking for setuptools for Windows...you can fetch an .exe from here...although it works with Python 2.X only...


0

#26 User is offline   gonagi 

  • New Member
  • Pip
  • Group: Members
  • Posts: 3
  • Joined: 30-November 10

Posted 30 November 2010 - 08:32 PM

Hi,

I'm using Python 3.1.3 on Windows 7 32-bit.

When I installed tweepy 1.4-py3 and tried to authenticate the app,
I have got an error saying:

File "C:\Python31\lib\site-packages\tweepy-1.4-py3.1.egg\tweepy\auth.py", line 85, in get_authorization_url
raise TweepError(e)
tweepy.error.TweepError: HTTP Error 401: Unauthorized
-----
Do you have any idea about what I did wrong?
Could you tell me which version of Python and tweepy you are using?

Thanks in advance~~

QUOTE (arcticrobot @ Oct 7 2010, 08:06 AM) <{POST_SNAPBACK}>
I just compiled instruction on using tweepy with python 3 on windows machine:

1. I assume you have already installed python 3.1 on your windows machine and its located in C:\Python31. If not: please download and install it.

2. As with Linux example above download Tweepy for Python 3

3. To extract tar.gz file on windows machine download 7zip from 7-zip.org and install it.

4. Download distribute_setup.py and double click on it to install.

5. Create C:\tweepy directory

6. Open 7-zip GUI and navigate to the location of downloaded tweepy-1.4-py3.tar.gz . Click on it to open, then click on the .tar file inside it to get access to content. Extract contents of the .tar file to C:\tweepy

7. To properly set python variable on windows machine go to: My Computer(right click) -> Properties -> Advanced -> Environment Variables -> System Variables.
If you have PATH variable there, click Edit and add following to the line: ;C:\Python31 (note the semicolon in front of C)
If you don't have PATH variable there, click New, Variable Name: PATH, Variable Value: C:\Python31(no semicolon this time) OK your way out of variables.

8. Open your command prompt: Start -> Run... -> type "cmd" (do not include parentheses, they are only to refer to command"

9. Navigate to C:\tweepy where we previously extracted tweepy content by typing "cd C:\tweepy"

10. Install tweepy for Python 3 on windows by issuing "python setup.py install"

11. Now you can use tweepy with Python 3 on your Windows machine. I just tested it and it works.


0

#27 User is offline   JiggaKing 

  • New Member
  • Pip
  • Group: Members
  • Posts: 1
  • Joined: 18-December 10
  • Gender:Male

Posted 18 December 2010 - 08:27 AM

QUOTE (David Griffiths_1283427796 @ Sep 2 2010, 03:55 AM) <{POST_SNAPBACK}>
Good morning learners! :-)

I noticed this morning that Twitter have finally disabled a feature called "Basic Authentication" which allows you to easily post messages to Twitter.

Sound familiar? It should. We use it for posting Twitter messages in the code on Chapter 3.

But in the same way that eight-track tapes got replaced with these spiffy new "audio cassettes", Basic Authentication is now a thing of the past.

Bummer.

However, don't worry. We *have* found a workaround. Twitter is keen to keep your Tweet account as secure as possible and instead of using Basic Authentication, they are now using a newer system called "OAuth". OAuth is very cool, and very secure unfortunately it's... kind of tricky.

In fact it's been described as about as straightforward as performing brain surgery on a roller coaster.

Fortunately, there's a really useful guide on

http://jmillerinc.com/2010/05/31/twitter-f...on-using-oauth/

that tells you how to enable OAuth for your application. There's quite a few steps and we will get a similar set of instructions out in the next few days, in a more Head First style, but it's a great place to start.

By the end you should be able to replace the code from the book with something like this:

def send_to_twitter(msg):
import sys
import tweepy
CONSUMER_KEY = '...'
CONSUMER_SECRET = '...'
ACCESS_KEY = '...'
ACCESS_SECRET = '...'
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
api = tweepy.API(auth)
api.update_status(msg)



The CONSUMER_KEY, CONSUMER_SECRET, ACCESS_KEY and ACCESS_SECRET values need to need to some magic mojo that the above will tell you how to create.

If you drop the above code into your program in place of the send_to_twitter(msg) function in the book, you should find yourself back and Tweeting in no time.

DG


Hello Im a Pro newb at anything that has to do with programming but after hours of trying to install the tweppy to python 3.1 I am stuck here.

My code:

CONSUMER_KEY = 'xxxxxxxxxxxxxxxxxxxxx'
CONSUMER_SECRET = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
ACCESS_KEY = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
ACCESS_SECRET = 'xxxxxxxxxxxxxxxxxxxxxxxxxx'

auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
api = tweepy.API(auth)
api.update_status(sys.argv[1])

Response:

Traceback (most recent call last):
File "C:/tweepy/Enable Twiiter", line 12, in <module>
api.update_status(sys.argv[1])
IndexError: list index out of range

I think i am real close. Any suggestions?? Thx beforehand...





0

#28 User is offline   Structer 

  • New Member
  • Pip
  • Group: Members
  • Posts: 6
  • Joined: 29-December 10

Posted 29 December 2010 - 07:18 PM

QUOTE (arcticrobot @ Oct 7 2010, 08:06 AM) <{POST_SNAPBACK}>
I just compiled instruction on using tweepy with python 3 on windows machine:

1. I assume you have already installed python 3.1 on your windows machine and its located in C:\Python31. If not: please download and install it.

2. As with Linux example above download Tweepy for Python 3

3. To extract tar.gz file on windows machine download 7zip from 7-zip.org and install it.

4. Download distribute_setup.py and double click on it to install.

5. Create C:\tweepy directory

6. Open 7-zip GUI and navigate to the location of downloaded tweepy-1.4-py3.tar.gz . Click on it to open, then click on the .tar file inside it to get access to content. Extract contents of the .tar file to C:\tweepy

7. To properly set python variable on windows machine go to: My Computer(right click) -> Properties -> Advanced -> Environment Variables -> System Variables.
If you have PATH variable there, click Edit and add following to the line: ;C:\Python31 (note the semicolon in front of C)
If you don't have PATH variable there, click New, Variable Name: PATH, Variable Value: C:\Python31(no semicolon this time) OK your way out of variables.

8. Open your command prompt: Start -> Run... -> type "cmd" (do not include parentheses, they are only to refer to command"

9. Navigate to C:\tweepy where we previously extracted tweepy content by typing "cd C:\tweepy"

10. Install tweepy for Python 3 on windows by issuing "python setup.py install"

11. Now you can use tweepy with Python 3 on your Windows machine. I just tested it and it works.


I can not get past the python setup.py install step. I get a message that the setup tools doesn't exist. Please help!
0

#29 User is offline   Vandyke 

  • New Member
  • Pip
  • Group: Members
  • Posts: 1
  • Joined: 30-December 10

  Posted 30 December 2010 - 07:01 PM

QUOTE (Nilfur @ Oct 25 2010, 08:31 AM) <{POST_SNAPBACK}>
Thankyou arcticrobot for your detailed answer. It worked on my Windows Computer.

Since I am using Python 3, just as most of the people that read the "Head First" book, I had to change JMiller's code. I used the 2to3.py script to do so. It comes with Python 3 and is located at \Python31\Tools\Scripts.

If you do not want to do this yourself, here is the JMiller's sourceodoe for step 3:
CODE

import tweepy

CONSUMER_KEY = 'paste your Consumer Key here'
CONSUMER_SECRET = 'paste your Consumer Secret here'

auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth_url = auth.get_authorization_url()
print('Please authorize: ' + auth_url)
verifier = input('PIN: ').strip()
auth.get_access_token(verifier)
print("ACCESS_KEY = '%s'" % auth.access_token.key)
print("ACCESS_SECRET = '%s'" % auth.access_token.secret)


Thanks for the 2to3.py info!

I've been trying to duplicate this process on my Windows 7 machine ( can't learn as much from copy/paste).

Is there anyone here in the forums that could post a quick "step-by-step" on how to do this conversion?

Thanks in advance!
0

#30 User is offline   gonagi 

  • New Member
  • Pip
  • Group: Members
  • Posts: 3
  • Joined: 30-November 10

Posted 04 January 2011 - 03:53 AM

Thank you arcticrobot.

Now it's working perfect.
I think twitter server was unstable at that time.

QUOTE (gonagi @ Nov 30 2010, 08:32 PM) <{POST_SNAPBACK}>
Hi,

I'm using Python 3.1.3 on Windows 7 32-bit.

When I installed tweepy 1.4-py3 and tried to authenticate the app,
I have got an error saying:

File "C:\Python31\lib\site-packages\tweepy-1.4-py3.1.egg\tweepy\auth.py", line 85, in get_authorization_url
raise TweepError(e)
tweepy.error.TweepError: HTTP Error 401: Unauthorized
-----
Do you have any idea about what I did wrong?
Could you tell me which version of Python and tweepy you are using?

Thanks in advance~~


0

#31 User is offline   Core_500 

  • New Member
  • Pip
  • Group: Members
  • Posts: 1
  • Joined: 08-January 11

  Posted 08 January 2011 - 04:40 AM

Hi everyone

Don't skip chapter 3, it is very intresting, also a challange to resolve Twitters Basic vs OAuth.

Here are my solution and I hope it help you too :-)

I'm using Windows 7 and Python 3.1

I just downloaded Tweepy lib, which actually works with Python 3, from this link: http://tweepy.googlecode.com/files/tweepy-1.4-py3.tar.gz

Extract it with WinRAR or other, and then copy the Tweepy folder to your Python31\lib folder, that's it.

Now you can follow this link to test out Twitter AUTH with python: http://jeffmiller.github.com/2010/05/31/tw...hon-using-oauth


Here is the JMiller code, I just converted it to py3:


import tweepy

CONSUMER_KEY = 'paste your key here '
CONSUMER_SECRET = 'paste your key here '

auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth_url = auth.get_authorization_url()

print ('Please authorize:' + auth_url)

verifier = input('PIN: ').strip()
auth.get_access_token(verifier)

print ("ACCESS_KEY = '%s'" % auth.access_token.key)
print ("ACCESS_SECRET = '%s'" % auth.access_token.secret)



after you have acquired the ACCESS_KEY and ACCESS_SECRET, use following code to send message to your twitter account, again JMiller code.


import sys
import tweepy

CONSUMER_KEY = 'uVXxCvxC1Q7c6Rc05EIqQ'
CONSUMER_SECRET = 'GgQKUD1cbJiP5RdCAlAftNZE4mKmvbtwJzid82zswME'
ACCESS_KEY = '233499098-rRlFvevTGJxm8dUSDE5VJfwRqM3ELD3BjgnW7BoL'
ACCESS_SECRET = 'HMpp1MXU6BzhZrNZRvLR9zUxQwGsiMDTY3HnNVH0b9E'

auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
api = tweepy.API(auth)
api.update_status(sys.argv[1])




So people here is the complete code (solution to chapter 3) that works nice with Python3.1:


import sys
import tweepy
import urllib.request


def send_to_twitter(msg):
CONSUMER_KEY = 'paste your own key here'
CONSUMER_SECRET = 'paste your own key here'
ACCESS_KEY = 'paste your own key here'
ACCESS_SECRET = 'paste your own key here'

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!")




NB: You need to register your App with Twitter and install Tweepy lib in your Python31.

REMEMBER INDENDTS

God luck

kind regards
Al

This post has been edited by Core_500: 08 January 2011 - 04:43 AM

0

#32 User is offline   viola_blue 

  • New Member
  • Pip
  • Group: Members
  • Posts: 2
  • Joined: 11-January 11

Posted 12 January 2011 - 04:45 PM

Any solution to this? I am getting the same error message.

Traceback (most recent call last):
File "C:\Tweepy\setup.py", line 3, in (module)
from setuptools import setup, find_packages
importError: No module named setuptools

Any help would be greatly appreciated.
0

#33 User is offline   treeofcodes 

  • New Member
  • Pip
  • Group: Members
  • Posts: 1
  • Joined: 21-January 11

  Posted 21 January 2011 - 10:30 AM

I am using Mac OS X 10.6.6 and was wondering how could I install tweepy so that it works with Pyton 3.1, I am really eager to do this exercise, but I am having some difficulty understanding how to install this thing.
Thanks
0

#34 User is offline   dejiezz 

  • New Member
  • Pip
  • Group: Members
  • Posts: 1
  • Joined: 31-January 11

Posted 31 January 2011 - 02:56 AM

hey. can somebody help me about this error message?

CODE
C:\Documents and Settings\USER>C:\tweepy
Traceback (most recent call last):
File "C:\tweepy.py", line 3, in <module>
import tweepy
File "C:\tweepy.py", line 8, in <module>
auth = tweepy.OAuthHandler(gl76cI7lsxzICm61NwiEMw, iN6ccOb0odltHJYwfvdouWcG7
Xga3Ozj0qq7wEI1BOk )
AttributeError: 'module' object has no attribute 'OAuthHandler'


i've been install python31 and tweepy-1.7.1-py2.6 and i install it in windows XP 32bit
thx for your advice happy.gif
0

#35 User is offline   paulbarry 

  • Advanced Member
  • PipPipPipPipPipPipPipPip
  • Group: O'Reilly Author
  • Posts: 306
  • Joined: 20-August 09

Posted 02 February 2011 - 02:43 AM

QUOTE (dejiezz @ Jan 31 2011, 02:56 AM) <{POST_SNAPBACK}>
hey. can somebody help me about this error message?

CODE
C:\Documents and Settings\USER>C:\tweepy
Traceback (most recent call last):
File "C:\tweepy.py", line 3, in <module>
import tweepy
File "C:\tweepy.py", line 8, in <module>
auth = tweepy.OAuthHandler(gl76cI7lsxzICm61NwiEMw, iN6ccOb0odltHJYwfvdouWcG7
Xga3Ozj0qq7wEI1BOk )
AttributeError: 'module' object has no attribute 'OAuthHandler'


i've been install python31 and tweepy-1.7.1-py2.6 and i install it in windows XP 32bit
thx for your advice happy.gif


It looks like you have installed Tweepy for Python 2.6, not 3.1. Check back through this post to see specific advice for running on Python 3.

--Paul.
0

#36 User is offline   timbrown.net 

  • New Member
  • Pip
  • Group: Members
  • Posts: 1
  • Joined: 04-February 11

Posted 04 February 2011 - 10:24 AM

QUOTE (treeofcodes @ Jan 21 2011, 10:30 AM) <{POST_SNAPBACK}>
I am using Mac OS X 10.6.6 and was wondering how could I install tweepy so that it works with Pyton 3.1, I am really eager to do this exercise, but I am having some difficulty understanding how to install this thing.
Thanks


Here is my take on doing on a Mac.
http://www.timbrown.net/?p=926

Tim
0

#37 User is offline   SaviM 

  • New Member
  • Pip
  • Group: Members
  • Posts: 1
  • Joined: 24-February 11

Posted 24 February 2011 - 06:38 AM

This is such a helpful post! I'm a total newbie to Python and Twitter, just learning Python from this (excellent!) book, and I was able to follow your instructions and make it through chapter 3. Thank you!

QUOTE (Core_500 @ Jan 8 2011, 04:40 AM) <{POST_SNAPBACK}>
Hi everyone

Don't skip chapter 3, it is very intresting, also a challange to resolve Twitters Basic vs OAuth.

Here are my solution and I hope it help you too :-)

I'm using Windows 7 and Python 3.1

I just downloaded Tweepy lib, which actually works with Python 3, from this link: http://tweepy.googlecode.com/files/tweepy-1.4-py3.tar.gz

Extract it with WinRAR or other, and then copy the Tweepy folder to your Python31\lib folder, that's it.

Now you can follow this link to test out Twitter AUTH with python: http://jeffmiller.github.com/2010/05/31/tw...hon-using-oauth


Here is the JMiller code, I just converted it to py3:


import tweepy

CONSUMER_KEY = 'paste your key here '
CONSUMER_SECRET = 'paste your key here '

auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth_url = auth.get_authorization_url()

print ('Please authorize:' + auth_url)

verifier = input('PIN: ').strip()
auth.get_access_token(verifier)

print ("ACCESS_KEY = '%s'" % auth.access_token.key)
print ("ACCESS_SECRET = '%s'" % auth.access_token.secret)



after you have acquired the ACCESS_KEY and ACCESS_SECRET, use following code to send message to your twitter account, again JMiller code.


import sys
import tweepy

CONSUMER_KEY = 'uVXxCvxC1Q7c6Rc05EIqQ'
CONSUMER_SECRET = 'GgQKUD1cbJiP5RdCAlAftNZE4mKmvbtwJzid82zswME'
ACCESS_KEY = '233499098-rRlFvevTGJxm8dUSDE5VJfwRqM3ELD3BjgnW7BoL'
ACCESS_SECRET = 'HMpp1MXU6BzhZrNZRvLR9zUxQwGsiMDTY3HnNVH0b9E'

auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
api = tweepy.API(auth)
api.update_status(sys.argv[1])




So people here is the complete code (solution to chapter 3) that works nice with Python3.1:


import sys
import tweepy
import urllib.request


def send_to_twitter(msg):
CONSUMER_KEY = 'paste your own key here'
CONSUMER_SECRET = 'paste your own key here'
ACCESS_KEY = 'paste your own key here'
ACCESS_SECRET = 'paste your own key here'

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!")




NB: You need to register your App with Twitter and install Tweepy lib in your Python31.

REMEMBER INDENDTS

God luck

kind regards
Al


0

#38 User is offline   dok53 

  • New Member
  • Pip
  • Group: Members
  • Posts: 6
  • Joined: 20-March 11

Posted 05 April 2011 - 02:18 PM

hi there im new to this and was completly stuck on this part until i got to this forum(which has helped me soo much) but im a little stuck now just at the very end i have all the code working and the same as the examples on here..but i keep getting this....Traceback (most recent call last):
File "C:\Python32\twitter app", line 31, in <module>
send_to_twitter(get_price())
File "C:\Python32\twitter app", line 15, in send_to_twitter
api.update_status(msg)
File "C:\Python32\lib\tweepy\binder.py", line 153, in _call
raise TweepError(error_msg)
tweepy.error.TweepError: Twitter error response: status code = 401

can anyone help me please
Thanks in advance
0

#39 User is offline   dok53 

  • New Member
  • Pip
  • Group: Members
  • Posts: 6
  • Joined: 20-March 11

Posted 05 April 2011 - 02:51 PM

oh srry heres my code........
import sys
import tweepy
import urllib.request
import time

def send_to_twitter(msg):
CONSUMER_KEY ='dClfpVS4kVGJ8S9PJZMUrQ '
CONSUMER_SECRET = 'rIQAgDUmEjY9MwuB5CgaaOg3cmR1oCICMcM5mfiaUQ '
ACCESS_KEY = '270627237-YEZU3rqlcoltvUptDozYsYEwR5t4KTJMN5JnzMfX'
ACCESS_SECRET = 'a6hea1BCchUUbDJIhlptw61w198lhaofdii8wGx3fg'

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!")

This post has been edited by dok53: 05 April 2011 - 02:52 PM

0

#40 User is offline   paulbarry 

  • Advanced Member
  • PipPipPipPipPipPipPipPip
  • Group: O'Reilly Author
  • Posts: 306
  • Joined: 20-August 09

Posted 06 April 2011 - 12:58 AM

Hello folks!

From what we can work out, the Twitter folks have changed how applications interact with their service yet again.

Having initially changed the authentication mechanism just after we published (and breaking Chapter 3's examples in the process), Twitter have recently outlawed 3rd party clients (which is what the code in this thread and Chapter 3 lets you create). So... this may have killed the examples in this chapter permanently.

Why did Twitter do this? Who knows? But, they have certainly annoyed a lot of developers working in and around their service (not just us). Could we have predicted these types of problems when we wrote the book? Hardly. :-(

My advice to learners working through Chapter 3 is to work with the examples as provided, concentrating on the concepts covered regarding how data is passed into and out of functions. That's the real learning in the chapter. The interaction with Twitter was really just the icing-on-the-cake to make things fun. To get through the chapter, simply display the messages that you planned to send to Twitter on screen (and "pretend" that it was sent to Twitter).

So instead of these two lines of code at the end of the send_to_twitter() function:

resp  =  urllib.request.urlopen("http://twitter.com/statuses/update.json",  params)          
resp.read()

use this single line of code instead:

print(params)

It's not as much fun, but it will have to do.

To be really clear: the goal of Chapter 3 is not to send messages to Twitter. The goal of the chapter is to understand how functions work and how data is passed around and within programs. If you are getting that, then move onto Chapter 4 and keep learning. :-)

Regards.

--Paul.
0

Share this topic:


  • 3 Pages +
  • 1
  • 2
  • 3
  • 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