Python Programming - Creating A Twitter Retweet Bot w/ Tweepy

Sdílet
Vložit
  • čas přidán 23. 07. 2024
  • Welcome to Part 12 of the Python Programming tutorial series here on Tutorial Spot.
    In Part 12 I took inspiration from an article I saw online showing how a programmer had managed to win quite a few competitions using a Python script to automatically enter him into competitions on Twitter.
    I took the premise that we access the API from Twitter and simply search for tweets containing a certain keyword and then retweet the tweets found to contain that very keyword, or keywords!
    You will need to create a Twitter App and install Tweepy before using the code.
    Tweepy: github.com/tweepy/tweepy
    Twitter App Page: apps.twitter.com
    Code uploaded to PasteBin: pastebin.com/4yYJdVrn
    Python 3.6.4 was used to make this tutorial.
    Twitter: @TutorialSpotUK

Komentáře • 35

  • @chronicflashback6639
    @chronicflashback6639 Před 5 lety

    This is a very good tutorial, the only problem is that my bot retweets recent tweets that don´t meet the requirements(5 retweets) and it also tweets bots from days ago rather than current tweets, should I import time?

  • @SGEKidsGaming
    @SGEKidsGaming Před 6 lety +1

    Nice tutorial!
    Got a question: I've heard that the search functionality is being updated, the current method being deprecated in the next few months. Have you heard about that? Will we be able to use Tweepy in the future to search Twitter and Twitter users?

    • @TutorialSpotUK
      @TutorialSpotUK  Před 6 lety

      How is it being updated exactly? If they're added more functionality, then I imagine the core search feature through the API will stay pretty much the same, maybe.

  • @kclaire56
    @kclaire56 Před 5 lety +2

    Hi there thanks for tutorial if i wanted to like the status with out retweeting it what do i need to do

    • @kclaire56
      @kclaire56 Před 5 lety

      never mind i got it , tweet.favorite()

  • @ikweby9169
    @ikweby9169 Před 3 lety

    Great script - but how do you get it to loop? So for example it goes away and does 5 tweets, but while it runs what if another 5 tweets are done with the same search term? without re running the script it never finds them.
    How do you get around this?
    TIA

  • @jayden5718
    @jayden5718 Před 4 lety

    Can you search for hashtags ?

  • @a_m7ammad
    @a_m7ammad Před 5 lety

    nice tutorial u got like & subs but how I can let the bot retweet mine tweet ?

  • @RenanBauch
    @RenanBauch Před 4 lety

    Is that possible to make the bot run forever? or maybe in loop

  • @jgillanis
    @jgillanis Před 3 lety

    Instead of retweeting can I just replace tweet.retweet() with tweet.favorite()?

  • @KevPDj
    @KevPDj Před 6 lety

    what do I do if I get the error " tweepy not defined "

    • @TutorialSpotUK
      @TutorialSpotUK  Před 6 lety

      You need to install tweepy by the sounds of it. It's a bit of a pain to install, I'd recommend searching around online to find a tutorial. I tried many

    • @nnish_bz
      @nnish_bz Před 5 lety

      have you installed it?

  • @masaali1278
    @masaali1278 Před 5 lety

    thanks. how many tweets is it possible to retweet in an hour without facing an error?

    • @nag975
      @nag975 Před 4 lety

      it should always be below 40 ... read twitter rules

  • @elijahrotenberger7375
    @elijahrotenberger7375 Před 4 lety

    it keeps saying “StopIteration” is an invalid syntax? what did i do wrong?

  • @ingaregamingrevolution7750

    Can I retweet tweets from a twitter list?

  • @nag975
    @nag975 Před 5 lety +1

    Query : how to run this code every 15min and how can yo search for multiple key words ... I also hv a Raspberry pi ... thank you

    • @andrewkelly6444
      @andrewkelly6444 Před 4 lety

      I would like to know this as well

    • @Dimineko
      @Dimineko Před 4 lety

      why u just dont create a python code that create a subprocess that start with system that open the twitter bot.py every 15min?

    • @8urnside
      @8urnside Před 4 lety

      multiple criteria is just standard boolean e.g. python OR coding
      to run every 60 seconds, just add a while loop at the end of the program, assuming you still have function named main...
      while True:
      main()
      time.sleep(60)

  • @suriyamass3021
    @suriyamass3021 Před 4 lety

    Finally I Found Perfect Man

  • @MDreeezy
    @MDreeezy Před 4 lety

    Instructions unclear. How do I open that note pad thing at 3:13 where do i go for that

    • @cjs6502
      @cjs6502 Před 4 lety

      Ctrl+n

    • @statalog3388
      @statalog3388 Před 4 lety

      It's called 'Python Shell' or 'IDLE', then open a new file

  • @dominiccampos4471
    @dominiccampos4471 Před 6 lety +1

    Mine is not retweeting things but it does show the username.
    Can you help me?

    • @TutorialSpotUK
      @TutorialSpotUK  Před 6 lety

      Sorry for the late reply, did you ever get this fixed?

    • @masterjtricksters
      @masterjtricksters Před 6 lety

      I am having the same problem. It shows my name but nothing more. I tried doing a control+X on "user = api.me()
      print(user.name)" just to see what it would do without that command and it did nothing. If I find the issue I will let you know.

    • @masterjtricksters
      @masterjtricksters Před 6 lety

      So I looked into my own issue (the same issue Dominic Campos was having) and for me, I can't put in more than one search term. If I do, only my name shows up then it kicks me out. (I even tried just 2 terms and it didn't work) If I only put in one, it works and will retweet. So I am not sure if I am missing something? Here is my code: (with all search terms)
      import tweepy
      access_token = "You ain't getting my code!l"
      access_token_secret = "You ain't getting my code!"
      consumer_key = "You ain't getting my code!"
      consumer_secret = "You ain't getting my code!"
      auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
      auth.set_access_token(access_token, access_token_secret)
      api = tweepy.API(auth)
      user = api.me()
      print(user.name)
      def main():
      search = ("sciencediscoveries","internetdiscoveries","3dprinting","art",
      "computerscience","flyingcars","innovation","newtechnology",
      "supercomputers","inventions","technology","tech","science",
      "batteries","solar","ev","design","architecture")
      numberofTweets = 18
      for tweet in tweepy.Cursor(api.search, search).items(numberofTweets):
      try:
      tweet.retweet()
      print("Tweet Retweeted")
      except tweepy.TweepError as e:
      print(e.reason)
      except StopIterartion:
      break
      main()

    • @masterjtricksters
      @masterjtricksters Před 6 lety

      Looking into this more, it seems as though some search terms work and some don't. Like "internetdiscoveries" wont return anything but "3dprinter","science" together will.. Does this look for posts that have all the tags you mentioned or will it look for each on individually? If it does so alltogether do you suggestion I copy and past the def main () and everything below it to repeat another term? Message me in your spare time if you can.

    • @akhil9869
      @akhil9869 Před 5 lety

      @@masterjtricksters same issue

  • @Miles-Oldenburger
    @Miles-Oldenburger Před 5 lety

    i hope you changed those key's, you shouldn't publicly post them

    • @TutorialSpotUK
      @TutorialSpotUK  Před 5 lety +1

      Yeah, blurring them out in editing was difficult and looked ugly so I left them visible and regenerated my keys.