Follow User in Tweepy No Output










0















I have code in Python 3.6 and am trying to get this code to work, it's not picking up the tweets by the user I am following I have specified. I pulled the base structure of this from code I had functioning correctly that tracked keywords from the global twitter stream. Below is the line of code not functioning properly, due to it not picking up the stream.



stream.filter(follow=[user_id])


Here is the full code also as reference.



import settings
import tweepy
import dataset
import datetime
import time
from textblob import TextBlob
from sqlalchemy.exc import ProgrammingError
import json

print("Starting scraper.py")
db = dataset.connect(settings.CONNECTION_STRING)
print("Connected to dataset")

class StreamListener(tweepy.StreamListener):

def on_status(self, status):
print(status.text)
description = status.user.description
loc = status.user.location
text = status.text
coords = status.coordinates
geo = status.geo
name = status.user.screen_name
user_created = status.user.created_at
followers = status.user.followers_count
id_str = status.id_str
created = status.created_at
retweets = status.retweet_count
bg_color = status.user.profile_background_color
blob = TextBlob(text)
sent = blob.sentiment

if geo is not None:
geo = json.dumps(geo)

if coords is not None:
coords = json.dumps(coords)

table = db[settings.TABLE_NAME]
try:
table.insert(dict(
user_description=description,
user_location=loc,
coordinates=coords,
text=text,
geo=geo,
user_name=name,
user_created=user_created,
user_followers=followers,
id_str=id_str,
created=created,
retweet_count=retweets,
user_bg_color=bg_color,
polarity=sent.polarity,
subjectivity=sent.subjectivity,
))
except ProgrammingError as err:
print(err)

def on_error(self, status_code):
if status_code == 420:
# returning False in on_data disconnects the stream
return False

auth = tweepy.OAuthHandler(settings.TWITTER_APP_KEY, settings.TWITTER_APP_SECRET)
auth.set_access_token(settings.TWITTER_KEY, settings.TWITTER_SECRET)
api = tweepy.API(auth)

print("Running Stream Listener")
stream_listener = StreamListener()
stream = tweepy.Stream(auth=api.auth, listener=stream_listener)
user_id = 'ThomasC57976849'
print("Filtering Stream By User ", user_id)

ts = time.time()
#print(ts)
st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
print(st)

#stream.filter(follow=['NCDOT_I85'])
#stream.filter(follow=['hwytestacct'])
stream.filter(follow=[user_id])









share|improve this question


























    0















    I have code in Python 3.6 and am trying to get this code to work, it's not picking up the tweets by the user I am following I have specified. I pulled the base structure of this from code I had functioning correctly that tracked keywords from the global twitter stream. Below is the line of code not functioning properly, due to it not picking up the stream.



    stream.filter(follow=[user_id])


    Here is the full code also as reference.



    import settings
    import tweepy
    import dataset
    import datetime
    import time
    from textblob import TextBlob
    from sqlalchemy.exc import ProgrammingError
    import json

    print("Starting scraper.py")
    db = dataset.connect(settings.CONNECTION_STRING)
    print("Connected to dataset")

    class StreamListener(tweepy.StreamListener):

    def on_status(self, status):
    print(status.text)
    description = status.user.description
    loc = status.user.location
    text = status.text
    coords = status.coordinates
    geo = status.geo
    name = status.user.screen_name
    user_created = status.user.created_at
    followers = status.user.followers_count
    id_str = status.id_str
    created = status.created_at
    retweets = status.retweet_count
    bg_color = status.user.profile_background_color
    blob = TextBlob(text)
    sent = blob.sentiment

    if geo is not None:
    geo = json.dumps(geo)

    if coords is not None:
    coords = json.dumps(coords)

    table = db[settings.TABLE_NAME]
    try:
    table.insert(dict(
    user_description=description,
    user_location=loc,
    coordinates=coords,
    text=text,
    geo=geo,
    user_name=name,
    user_created=user_created,
    user_followers=followers,
    id_str=id_str,
    created=created,
    retweet_count=retweets,
    user_bg_color=bg_color,
    polarity=sent.polarity,
    subjectivity=sent.subjectivity,
    ))
    except ProgrammingError as err:
    print(err)

    def on_error(self, status_code):
    if status_code == 420:
    # returning False in on_data disconnects the stream
    return False

    auth = tweepy.OAuthHandler(settings.TWITTER_APP_KEY, settings.TWITTER_APP_SECRET)
    auth.set_access_token(settings.TWITTER_KEY, settings.TWITTER_SECRET)
    api = tweepy.API(auth)

    print("Running Stream Listener")
    stream_listener = StreamListener()
    stream = tweepy.Stream(auth=api.auth, listener=stream_listener)
    user_id = 'ThomasC57976849'
    print("Filtering Stream By User ", user_id)

    ts = time.time()
    #print(ts)
    st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
    print(st)

    #stream.filter(follow=['NCDOT_I85'])
    #stream.filter(follow=['hwytestacct'])
    stream.filter(follow=[user_id])









    share|improve this question
























      0












      0








      0








      I have code in Python 3.6 and am trying to get this code to work, it's not picking up the tweets by the user I am following I have specified. I pulled the base structure of this from code I had functioning correctly that tracked keywords from the global twitter stream. Below is the line of code not functioning properly, due to it not picking up the stream.



      stream.filter(follow=[user_id])


      Here is the full code also as reference.



      import settings
      import tweepy
      import dataset
      import datetime
      import time
      from textblob import TextBlob
      from sqlalchemy.exc import ProgrammingError
      import json

      print("Starting scraper.py")
      db = dataset.connect(settings.CONNECTION_STRING)
      print("Connected to dataset")

      class StreamListener(tweepy.StreamListener):

      def on_status(self, status):
      print(status.text)
      description = status.user.description
      loc = status.user.location
      text = status.text
      coords = status.coordinates
      geo = status.geo
      name = status.user.screen_name
      user_created = status.user.created_at
      followers = status.user.followers_count
      id_str = status.id_str
      created = status.created_at
      retweets = status.retweet_count
      bg_color = status.user.profile_background_color
      blob = TextBlob(text)
      sent = blob.sentiment

      if geo is not None:
      geo = json.dumps(geo)

      if coords is not None:
      coords = json.dumps(coords)

      table = db[settings.TABLE_NAME]
      try:
      table.insert(dict(
      user_description=description,
      user_location=loc,
      coordinates=coords,
      text=text,
      geo=geo,
      user_name=name,
      user_created=user_created,
      user_followers=followers,
      id_str=id_str,
      created=created,
      retweet_count=retweets,
      user_bg_color=bg_color,
      polarity=sent.polarity,
      subjectivity=sent.subjectivity,
      ))
      except ProgrammingError as err:
      print(err)

      def on_error(self, status_code):
      if status_code == 420:
      # returning False in on_data disconnects the stream
      return False

      auth = tweepy.OAuthHandler(settings.TWITTER_APP_KEY, settings.TWITTER_APP_SECRET)
      auth.set_access_token(settings.TWITTER_KEY, settings.TWITTER_SECRET)
      api = tweepy.API(auth)

      print("Running Stream Listener")
      stream_listener = StreamListener()
      stream = tweepy.Stream(auth=api.auth, listener=stream_listener)
      user_id = 'ThomasC57976849'
      print("Filtering Stream By User ", user_id)

      ts = time.time()
      #print(ts)
      st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
      print(st)

      #stream.filter(follow=['NCDOT_I85'])
      #stream.filter(follow=['hwytestacct'])
      stream.filter(follow=[user_id])









      share|improve this question














      I have code in Python 3.6 and am trying to get this code to work, it's not picking up the tweets by the user I am following I have specified. I pulled the base structure of this from code I had functioning correctly that tracked keywords from the global twitter stream. Below is the line of code not functioning properly, due to it not picking up the stream.



      stream.filter(follow=[user_id])


      Here is the full code also as reference.



      import settings
      import tweepy
      import dataset
      import datetime
      import time
      from textblob import TextBlob
      from sqlalchemy.exc import ProgrammingError
      import json

      print("Starting scraper.py")
      db = dataset.connect(settings.CONNECTION_STRING)
      print("Connected to dataset")

      class StreamListener(tweepy.StreamListener):

      def on_status(self, status):
      print(status.text)
      description = status.user.description
      loc = status.user.location
      text = status.text
      coords = status.coordinates
      geo = status.geo
      name = status.user.screen_name
      user_created = status.user.created_at
      followers = status.user.followers_count
      id_str = status.id_str
      created = status.created_at
      retweets = status.retweet_count
      bg_color = status.user.profile_background_color
      blob = TextBlob(text)
      sent = blob.sentiment

      if geo is not None:
      geo = json.dumps(geo)

      if coords is not None:
      coords = json.dumps(coords)

      table = db[settings.TABLE_NAME]
      try:
      table.insert(dict(
      user_description=description,
      user_location=loc,
      coordinates=coords,
      text=text,
      geo=geo,
      user_name=name,
      user_created=user_created,
      user_followers=followers,
      id_str=id_str,
      created=created,
      retweet_count=retweets,
      user_bg_color=bg_color,
      polarity=sent.polarity,
      subjectivity=sent.subjectivity,
      ))
      except ProgrammingError as err:
      print(err)

      def on_error(self, status_code):
      if status_code == 420:
      # returning False in on_data disconnects the stream
      return False

      auth = tweepy.OAuthHandler(settings.TWITTER_APP_KEY, settings.TWITTER_APP_SECRET)
      auth.set_access_token(settings.TWITTER_KEY, settings.TWITTER_SECRET)
      api = tweepy.API(auth)

      print("Running Stream Listener")
      stream_listener = StreamListener()
      stream = tweepy.Stream(auth=api.auth, listener=stream_listener)
      user_id = 'ThomasC57976849'
      print("Filtering Stream By User ", user_id)

      ts = time.time()
      #print(ts)
      st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
      print(st)

      #stream.filter(follow=['NCDOT_I85'])
      #stream.filter(follow=['hwytestacct'])
      stream.filter(follow=[user_id])






      python twitter streaming tweepy username






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 13 '18 at 20:17









      Daniel RoyerDaniel Royer

      4510




      4510






















          0






          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53288851%2ffollow-user-in-tweepy-no-output%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53288851%2ffollow-user-in-tweepy-no-output%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          這個網誌中的熱門文章

          How to read a connectionString WITH PROVIDER in .NET Core?

          In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

          Museum of Modern and Contemporary Art of Trento and Rovereto