Nov-01-2018, 01:09 PM
Hi guys,
I have the below "Twitter listen" Python script running on my Raspberry Pi. When it is running it is simply listening for tweets from a specific user based on the Id. But I need to change that Id dynamic (look at the last code line), maybe from the "def on_success"!?
But how do I do that? Any help will be appreciated.
I have the below "Twitter listen" Python script running on my Raspberry Pi. When it is running it is simply listening for tweets from a specific user based on the Id. But I need to change that Id dynamic (look at the last code line), maybe from the "def on_success"!?
But how do I do that? Any help will be appreciated.
# coding=utf-8
#!/usr/bin/env python
import os
import sys
import requests
import time
import datetime
from os import path
from twython import TwythonStreamer
from auth import (
consumer_key,
consumer_secret,
access_token,
access_token_secret
)
from twython import Twython
class MyStreamer(TwythonStreamer):
print("starting")
#print(DATABASE_URL)
def on_success(self, data):
if 'text' in data:
#get handleID from tweet
userid = data['user']['id_str']
stream = MyStreamer(
consumer_key,
consumer_secret,
access_token,
access_token_secret
)
twitter = Twython(
consumer_key,
consumer_secret,
access_token,
access_token_secret
)
stream.statuses.filter(follow='123456789') #This should be dynamic = userid
