simplesi
Posts: 2327
Joined: Fri Feb 24, 2012 6:19 pm
Location: Euxton, Lancashire, UK
Contact: Website

Easiest way to get a Python prog to receive a T'internet msg

Sun Dec 14, 2014 10:53 pm

I want to stick a Model A+ with Unicorn hat at top of tree underneath our Angel and tweet/whatsapp/sms (any muggle friendly app will do) so I can change the colour of the leds.

I'm a Python person so would like to do it in that (and then maybe extend to ScratchGPIO!)

ideas?

Simon
Seeking help with Scratch and I/O stuff for Primary age children
http://cymplecy.wordpress.com/ @cymplecy on twitter

toxibunny
Posts: 1382
Joined: Thu Aug 18, 2011 9:21 pm

Re: Easiest way to get a Python prog to receive a T'internet

Sun Dec 14, 2014 11:32 pm

this is a really good question, and I'm sorry to say I don't know, apart from it probably has something to do with tcp, udp, and/or sockets, if they're not already the same thing.

I bought one of those esp8266 modules the other day, and it's really revealed a pretty big gap in my knowledge. I've been doing a little bit of reading, but haven't really grokked it yet...
note: I may or may not know what I'm talking about...

DirkS
Posts: 10292
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: Easiest way to get a Python prog to receive a T'internet

Sun Dec 14, 2014 11:36 pm

Possible starting point: http://blog.whaleygeek.co.uk/twurtle/

Gr.
Dirk.

simplesi
Posts: 2327
Joined: Fri Feb 24, 2012 6:19 pm
Location: Euxton, Lancashire, UK
Contact: Website

Re: Easiest way to get a Python prog to receive a T'internet

Sun Dec 14, 2014 11:42 pm

@dirk - Ta - I'll read up on twitter modules

Simon
Seeking help with Scratch and I/O stuff for Primary age children
http://cymplecy.wordpress.com/ @cymplecy on twitter

simplesi
Posts: 2327
Joined: Fri Feb 24, 2012 6:19 pm
Location: Euxton, Lancashire, UK
Contact: Website

Re: Easiest way to get a Python prog to receive a T'internet

Mon Dec 15, 2014 12:11 am

Ended up following
http://www.makeuseof.com/tag/how-to-bui ... itter-bot/ (Note instructions slightly outdated so you need to interpret and modify slightly - main one is that it wnted me to authorise my phone)

and got it reading my timeline using

Code: Select all

#!/usr/bin/env python
import sys
from twython import Twython
CONSUMER_KEY = 'cxcvcvx2'
CONSUMER_SECRET = 'ffdfgdfgdfgdf
ACCESS_KEY = 'dfgdfgdg'
ACCESS_SECRET = dfgdgdgdfgdf'

twitter = Twython(CONSUMER_KEY,CONSUMER_SECRET,ACCESS_KEY,ACCESS_SECRET) 

print twitter.get_home_timeline()
so I should be off to the races
Seeking help with Scratch and I/O stuff for Primary age children
http://cymplecy.wordpress.com/ @cymplecy on twitter

simplesi
Posts: 2327
Joined: Fri Feb 24, 2012 6:19 pm
Location: Euxton, Lancashire, UK
Contact: Website

Re: Easiest way to get a Python prog to receive a T'internet

Mon Dec 15, 2014 8:25 am

And this shows how to receive a tweet :)
https://learn.sparkfun.com/tutorials/ra ... er-monitor
Seeking help with Scratch and I/O stuff for Primary age children
http://cymplecy.wordpress.com/ @cymplecy on twitter

simplesi
Posts: 2327
Joined: Fri Feb 24, 2012 6:19 pm
Location: Euxton, Lancashire, UK
Contact: Website

Re: Easiest way to get a Python prog to receive a T'internet

Mon Dec 15, 2014 4:13 pm

@forToffee showed me this
http://fortoffee.org.uk/2014/12/a-cheer ... tmas-tree/

which is easier to do as no Twitter authorisation needed but then my Pi is not totally under my control :)

Simon
Seeking help with Scratch and I/O stuff for Primary age children
http://cymplecy.wordpress.com/ @cymplecy on twitter

simplesi
Posts: 2327
Joined: Fri Feb 24, 2012 6:19 pm
Location: Euxton, Lancashire, UK
Contact: Website

Re: Easiest way to get a Python prog to receive a T'internet

Tue Dec 16, 2014 1:08 pm

So i've added in #cheerlights into ScratchGPIO but still looking for a ways of interacting normal muggles to an #Iot Pi device :)

http://simplesi.net/cheerlights-support ... -dev-only/
Seeking help with Scratch and I/O stuff for Primary age children
http://cymplecy.wordpress.com/ @cymplecy on twitter

User avatar
DougieLawson
Posts: 38448
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Easiest way to get a Python prog to receive a T'internet

Tue Dec 16, 2014 1:50 pm

simplesi wrote:So i've added in #cheerlights into ScratchGPIO but still looking for a ways of interacting normal muggles to an #Iot Pi device :)

http://simplesi.net/cheerlights-support ... -dev-only/
Ah, that explains some of the obscure tweets from Dr. Andy Stanford-Clark (@andysc) that I've been seeing.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

I'll do your homework for you for a suitable fee.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

danarashad
Posts: 33
Joined: Fri Jan 09, 2015 4:04 pm

Re: Easiest way to get a Python prog to receive a T'internet

Mon Jan 12, 2015 4:23 am

simplesi wrote:Ended up following
http://www.makeuseof.com/tag/how-to-bui ... itter-bot/ (Note instructions slightly outdated so you need to interpret and modify slightly - main one is that it wnted me to authorise my phone)

and got it reading my timeline using

Code: Select all

#!/usr/bin/env python
import sys
from twython import Twython
CONSUMER_KEY = 'cxcvcvx2'
CONSUMER_SECRET = 'ffdfgdfgdfgdf
ACCESS_KEY = 'dfgdfgdg'
ACCESS_SECRET = dfgdgdgdfgdf'

twitter = Twython(CONSUMER_KEY,CONSUMER_SECRET,ACCESS_KEY,ACCESS_SECRET) 

print twitter.get_home_timeline()
so I should be off to the races
I am trying to get this to work. But I keep receiving the following errors.

[email protected](none) ~/TwitterTest $ python d.py 'Hello Twitterverse'
Traceback (most recent call last):
File "d.py", line 9, in <module>
api.update_status(status=sys.argv[1])
File "/usr/local/lib/python2.7/dist-packages/twython/endpoints.py", line 107, in update_status
return self.post('statuses/update', params=params)
File "/usr/local/lib/python2.7/dist-packages/twython/api.py", line 267, in post
return self.request(endpoint, 'POST', params=params, version=version)
File "/usr/local/lib/python2.7/dist-packages/twython/api.py", line 257, in request
api_call=url)
File "/usr/local/lib/python2.7/dist-packages/twython/api.py", line 198, in _request
retry_after=response.headers.get('X-Rate-Limit-Reset'))
twython.exceptions.TwythonAuthError: Twitter API returned a 401 (Unauthorized), Could not authenticate you

What if anything am I doing wrong. I followed the directions from the link you posted. I have the correct access keys from twitter. Thanks for any help. Raspberry Pi b+, I don't know if that has anything to do with it not working.

simplesi
Posts: 2327
Joined: Fri Feb 24, 2012 6:19 pm
Location: Euxton, Lancashire, UK
Contact: Website

Re: Easiest way to get a Python prog to receive a T'internet

Mon Jan 12, 2015 7:11 am

Well my code prints tweets - you seem to be wanting to send a tweet
Can you show us your code and I'll try it with my creds
Simon
Seeking help with Scratch and I/O stuff for Primary age children
http://cymplecy.wordpress.com/ @cymplecy on twitter

User avatar
DougieLawson
Posts: 38448
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Easiest way to get a Python prog to receive a T'internet

Mon Jan 12, 2015 12:40 pm

The problem is that danarashad has failed to get the OAuth2 stuff done to register his application, get the four keys (consumer_key, consumer_secret, access_token, access_token_secret) and run the OAuth callback process.

The Twython documentation is very much lacking details of how to do that. There's one more reason to use Tweepy.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

I'll do your homework for you for a suitable fee.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

DavidMS
Posts: 139
Joined: Fri May 25, 2012 8:48 pm
Contact: Website

Re: Easiest way to get a Python prog to receive a T'internet

Mon Jan 12, 2015 12:47 pm

Have a look this is would be quite easy to modify to what you are looking for, I think

http://www.raspberrypi.org/forums/viewt ... 32&t=95987
http://meanderingpi.wordpress.com/
11 Raspberry Pi's and counting....

danarashad
Posts: 33
Joined: Fri Jan 09, 2015 4:04 pm

Re: Easiest way to get a Python prog to receive a T'internet

Mon Jan 12, 2015 7:58 pm

DougieLawson wrote:The problem is that danarashad has failed to get the OAuth2 stuff done to register his application, get the four keys (consumer_key, consumer_secret, access_token, access_token_secret) and run the OAuth callback process.

The Twython documentation is very much lacking details of how to do that. There's one more reason to use Tweepy.
I can try to run the OAuth callback process. I have the four keys, I'll figure out how to run the OAuth callback process. Thanks for all the help. By the way is Raspberry Pi big in the UK? I am in America and it seems like a lot of the help is coming out of the UK.

User avatar
DougieLawson
Posts: 38448
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Easiest way to get a Python prog to receive a T'internet

Mon Jan 12, 2015 8:08 pm

danarashad wrote: I can try to run the OAuth callback process. I have the four keys, I'll figure out how to run the OAuth callback process. Thanks for all the help. By the way is Raspberry Pi big in the UK? I am in America and it seems like a lot of the help is coming out of the UK.
It's a British design for a British university, made by a British company in Wales. So it's just ever so slightly British and ever so slightly popular over here in Blighty.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

I'll do your homework for you for a suitable fee.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

danarashad
Posts: 33
Joined: Fri Jan 09, 2015 4:04 pm

Re: Easiest way to get a Python prog to receive a T'internet

Tue Jan 13, 2015 2:52 am

DougieLawson wrote:
danarashad wrote: I can try to run the OAuth callback process. I have the four keys, I'll figure out how to run the OAuth callback process. Thanks for all the help. By the way is Raspberry Pi big in the UK? I am in America and it seems like a lot of the help is coming out of the UK.
It's a British design for a British university, made by a British company in Wales. So it's just ever so slightly British and ever so slightly popular over here in Blighty.
Thanks, I got it working now.
I had to change
ACCESS_KEY = '***************YOUR DATA*****************'
to OAUTH_TOKEN=''
And I changed ACCESS_SECRET = '***************YOUR DATA*****************'
to OAUTH_TOKEN_SECRET=''.
Works like a charm. Again thanks for the help.
The link where I started the project.
http://www.makeuseof.com/tag/how-to-bui ... itter-bot/
And go Blighty I have been wanted a Pi then finally bought one.

Return to “Python”