Code Monkey home page Code Monkey logo

twitter-bot-post-images's Introduction

twitter-bot-post-images

A Twitter bot that posts/tweets images/videos once every hour. This script is used to automate posts for the @hourlytakasugi twitter account.

Steps:

  1. You need to get a Developer Account first. This will give you some authentication keys that we will need to run the code. It is very simple to get a Developer Account, you just need to fill in some information about what your bot is going to do. To get a Developer Account, you can follow Steps 1-4 from the website here
  2. Once you have a Developer Account, edit values in twitter-bot-tweet-images.py with your own keys and image directory. The comments will help you understand which variables to edit.
  3. Now run the code! Command: python3 twitter-bot-tweet-images.py
  4. The code runs forever. So you'll need a machine which can keep it running. I run it inside tmux on AWS.
  5. The code can tweet images and videos of most extensions (.png, .mp4, .gif, .jpg, .jpeg etc). Regarding videos, it can upload small videos, but larger videos might require some code modification. You'll have to test it out! To see size limit for images/videos, see this documentation.

FAQ/Notes:

  1. This code works with the Free version of the Developer Account. That is, you will have v2 Access, and Limited v1.1 Access. This is enough for our needs.
  2. If you want to include a caption with your image in the tweet, simply do: response = client_v2.create_tweet(text="my caption", media_ids=[media.media_id])
  3. If you want to insert more than one image in the tweet (upto 4 images), you'll have to get a media-id for each image. Then, replace the code with response = client_v2.create_tweet(text="my caption", media_ids=[media1.media_id, media2.media_id, media3.media_id, media4.media_id])
  4. In the Developer Portal, make sure you edit the "User authentication set up" so that you have both "Read and Write" permissions. Regenerate your authentication keys if you make such a change.
  5. Again, under "User authentication set up", you can set the callback url as http://127.0.0.1:5000/oauth/callback ; Regenerate your authentication keys if you make such a change.
  6. Since an image is chosen randomly, there can be repeats before the entire list is exhausted. If you don't want to repeat images, I just use os.rename or shutil.move to move the tweeted file to another directory, say backup_dir. Once all the images have been tweeted, then image_folder will be empty. Now you can move all the files from backup_dir to image_folder and the process will start over. The code for this is simple so in case you need it, I will be happy to provide it.
  7. Please raise issues in case you need any help! Good luck!

twitter-bot-post-images's People

Contributors

saumya-gupta-26 avatar

Stargazers

Peijin Li avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.