0

Total noob with Python writing, so pease be kind. I have been trying for hours to solve this and so long I am not able. The only work I have done in Python was much simpler and didn't involve libraries.

I'm using this Python code to implement an Arduino action on my Yún. It is based on Tweepy library. My main goal is to insert three hashtags and do 3 different things in Arduino depending on which hashtag has been tweeted. So, everything is working fine and my LED is blinking whenever any of the hashtag is tweeted. What I want to do now is bisect code to be run on Arduino.

This is part of my streaming.py code:

search_string = '#jekotest'

class StdOutListener(StreamListener):

"""
A listener handles tweets are the received from the stream.
This is a basic listener that just prints received tweets to stdout.
"""

def on_data(self, data):
    # I call an external script because the Arduino's Bridge library
    # confilcts with the tweepy library
    call(["/usr/bin/python", script_path + "/go.py"])
    return True

def on_error(self, status):
    # TODO: Put some error handling here
    return False

if __name__ == '__main__':
    l = StdOutListener()
    auth = OAuthHandler(consumer_key, consumer_secret)
    auth.set_access_token(access_token, access_token_secret)

    stream = Stream(auth, l)
    stream.filter(track=[search_string])

And this is go.py:

import sys
sys.path.insert(0, '/usr/lib/python2.7/bridge/')

from bridgeclient import BridgeClient as bridgeclient

value = bridgeclient()
value.put('go','1')

I know that stream.body is a dict containing {'track': '#jekotest'} so: How the heck could I do a

if '#jekotest' in stream.body:
value.put('go', 1)
elif: 
'#anotherhashtag' in stream.body
value.put('go', 2)

And so on?

Thank you so much

Graucho Marx
  • 61
  • 1
  • 8
  • OK, first point achieved. I'm passing an argument on the call. Now I need to know which hashtag is firing the call in order to take different paths. Still working on it, any thought on tweepy would be appreciated. – Graucho Marx Feb 10 '16 at 12:32
  • Not exactly the solution I was looking for, but it is a solution (specially for total noobs like me): just pass an argument with the call to the go.py file: `call(["/usr/bin/python", script_path + "/go.py, myArgument"])` – Graucho Marx Feb 15 '16 at 19:00

1 Answers1

0

Finally, I managed to put both files together and make it work like this:

hashtag = status.entities['hashtags']
    for value in hashtag:
        if translateHashtag1 in value['text']:
            goBridge.put('go', 1)
Graucho Marx
  • 61
  • 1
  • 8