Jump to content


Photo

Send_to_twitter - Chapter 3, Solved


  • Please log in to reply
3 replies to this topic

#1 Mahesh Deshreddy

Mahesh Deshreddy

    New Member

  • Members
  • Pip
  • 4 posts

Posted 26 January 2015 - 04:53 AM

Hello Head First Readers,

My Name is Mahesh and I am just a beginner to programming like you... After working around 2 days on twitter chapter finally am succeeded on that!
Yup its a big hectic process and I will try to explain, If you find any difficulty on that then please let me know :)

In a book we see twitters basic authentication code and now it is outdated, I request to Paul Barry and David Griffiths that please release a second edition with updated codes.

Please follow below steps:
1. First you need to create a New Twitter App!, to get Consumer Key, Consumer Secret, Access token and Token Key.(Warning: Do not post or give these things to anyone!)

2. Follow these below steps in CMD(Command Promt)
a)cd Python34 (Here Python34 is an Version, its 3.4.2)
b)cd Scripts

3. After second step it looks like this - C:\Python34\Scripts>

4. C:\Python34\Scripts>easy_install.exe twitter

5. Now time to create program like below

from twitter import *
import urllib.request
import time
CONSUMER_KEY = 'XXXXXXXXXXXXXXXXXXXXXXXX'
CONSUMER_SECRET = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
ACCESS_TOKEN_KEY= 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
ACCESS_TOKEN_SECRET= 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'

def get_price():
page = urllib.request.urlopen("http://beans-r-us.ap...s-loyalty.html")
text = page.read().decode("utf8")

Where = text.find(">$")
Starting_Price = Where + 2
End_of_Price = Starting_Price + 4
return float(text[Starting_Price:End_of_Price])

def send_to_twitter():
t = Twitter(auth=OAuth(ACCESS_TOKEN_KEY, ACCESS_TOKEN_SECRET, CONSUMER_KEY, CONSUMER_SECRET))
t.statuses.update(status=get_price())

def msg():
t = Twitter(auth=OAuth(ACCESS_TOKEN_KEY, ACCESS_TOKEN_SECRET, CONSUMER_KEY, CONSUMER_SECRET))
t.statuses.update(status="Best time to Buy!")

price_now = input("Do you want to check the price now?(Y/N) - ")

if price_now == "Y":
send_to_twitter()
else:
price = 99.99
while price > 4.25:
time.sleep(5)
price = get_price()
print(price)
msg()

6. In above program you need to update your keys in-place of 'XXXXXXXXXXXXXXXXXXXX'

Thats it You are good to go! ;)

If you find this helpful then please like and become a follower in my twitter account(https://twitter.com/Maheshdeshreddy)


Thanks

#2 Kyle Hayden

Kyle Hayden

    New Member

  • Members
  • Pip
  • 1 posts

Posted 02 February 2015 - 04:19 PM

Is there a solution to this problem for Mac? Thank you

#3 Mahesh Deshreddy

Mahesh Deshreddy

    New Member

  • Members
  • Pip
  • 4 posts

Posted 02 February 2015 - 10:49 PM

Is there a solution to this problem for Mac? Thank you


Hi Kyle,

First Have you got 4 keys which is mentioned in the program? If not go to below link and sign in then click create new app,
https://apps.twitter.com/

Just fill out the details, when you get in then change permission to "Read and Write(Third option)" and note down all 4 keys.

Next try to run program by updating those 4 keys.

If you see any error then u need work around to install Python Twitter Tools in your Mac system! Check below link for some discussions but am not sure
http://stackoverflow...pip-on-mac-os-x

You should run command prompt as administrator.

Let me know if you find any problems, I will try to work around.

See you

#4 #TM#

#TM#

    Active Member

  • Members
  • PipPipPip
  • 91 posts
  • Gender:Not Telling

Posted 16 March 2015 - 07:41 AM

If somebody still having trouble on sending messages to twitter (chapter3 problem) follow my updated blog link.

 

MY UPDATED BLOG LINK

 

Enjoy!!! cool.png smile.png 






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users