I'm using the tweepy API and want to return the data found, pass it to the Giphy API function and use it as a query for the giphy search.
class TweetStreamListener(StreamListener):
# on success
def on_data(self, data):
# decode json
dict_data = json.loads(data)
# pass tweet into TextBlob
tweet = TextBlob(dict_data["text"])
# output sentiment polarity
print (tweet.sentiment.polarity)
# determine if sentiment is positive, negative, or neutral
if tweet.sentiment.polarity < 0:
sentiment = "negative"
elif tweet.sentiment.polarity == 0:
sentiment = "neutral"
else:
sentiment = "positive"
# output sentiment
print (sentiment)
return(sentiment)
The sentiment value above is what I want to return from the class and pass to the GIPHY API Functions
# Giphy API Functions
def setup():
url = api + apiKey + query
print("Getting data with query 'sentiment'")
json.loads(url, my_callback)
def my_callback(data):
print("Data recieved!")
print(data.data[0].images.original.url)
I was thinking of creating a new file for the giphy functions but can I add them to this one?
NOTE: I thought the following line would return the sentiment value
query = "&q=" + str(TweetStreamListener.on_data)
print(query)
NOTE: Instead I was given this,"&q=function TweetStreamListener.on_data at 0x1065c3268"
The on_data method takes one argument but you try to print the method itself and not the result. I am not familiar with the TweetStream api but you should have a look at this: https://www.dataquest.io/blog/streaming-data-python/