I am the proud owner of Nu Metal Hourly on twitter that has been running since October 2021!

On April 2023: CBDQ got shutdown and thus making hourly picture bots pretty hard to code!

I am no expert at coding but I wanted to spread the gospel to anyone who wants to have a go at making a pictures bot on twitter! (and perhaps on other websites too like Mastodon and Tumblr)

A HUGE thank you to this wonderful person for making it an easy process (as seen on this GitHub page):

ALL CREDITS TO THEM!


What you will need

A computer (this is not mobile friendly!)

Imgur account

Replit account

Twitter Developer account

Uptimerobot account


Gathering your pictures database in one place!

In order for your bot to fetch your pictures smoothly, we need to put them all in one place online!

This is where making an Imgur account will come in handy

Adding pictures on Imgur

After making your account: click on your username on the top-right of the page (1), and then 'Posts' (2)

You can now go ahead and click on 'New post' on the top-left of the page and upload your pictures!

Tip: You can upload multiple pictures at once in order for the procces to go faster!

And now your pictures on Imgur are ready to be added to the bot!


Hosting your bot on Replit!

(This part was brought you by this tutorial)

Replit is where all your coding will come together and bring your bot to life!

Once you have made your account: click on '+ Create Repl' to get started!

Next, choose 'Python' in the template section (1) , name your bot (2) and click on '+ Create Repl' (3)

This is the page where all your codes will be, so make sure to bookmark it if you want to update it later!

The upper-left section is what we will be working with next

You can now copy and paste (ctrl+v) this code on the first line of main.py (1) and then run it (2) and let it run until it stops (3)

On the top-left of your screen you can click on the 'New File' icon (1) and name it 'cred.json' and Enter (2)

You can now copy and paste (ctrl+v) this code on the first line of your cred.json code

Same thing again but this time we are making a new file named 'keep_alive.py'

You can now copy and paste (ctrl+v) this code on the first line of your keep_alive.py code

This time we are making a new file named 'example.env'

You can now copy and paste (ctrl+v) this code on the first line of your example.env code


Adding your images to your bot

We will be creating yet another file on Replit and naming it 'bot.json'

You can copy and paste (ctrl+v) this template on the first line of your bot.json code

You can also take a look at the full nu metal hourly code to see what it will look like once you've gathered all of your images together! (it has around 1.5k images)

Linking your images from Imgur

On Imgur: go to your 'Posts' by clicking on your username

Now click on one of your 'Posts': the little number on the right of the post is how many pictures your post has, for example, this one has 42!

On the picture: right click on it and then click on 'Copy Image Link': this will be the image link that you will be putting on your code for the individual picture

Scroll down to see the rest of the images on your post!

On your bot.json code on Replit, you can paste that image link on your code like this:

"{img yourimagelinkhere}",

or using my example image:

"{img https://i.imgur.com/MiPaXH0.jpg}",

Each line of code is 1 image, for example, my template has 16 images

If it's the last image on your code, always remove the comma at the end

If you want to add a new image: just put the comma again and skip a line for your next line of code aka your next image

Or simply replace the images links from my template with yours!


Having a Twitter developer account!

This is how the program we're going to bring to life will be able to post on Twitter automatically...for free!

First, click on this link and scroll down to 'Sign up for Free Account'

Twitter will then ask you to describe the purpose of your account in 250 characters: simply state that it will be a bot that will post pictures of your choosen subject, that it's non-profit and that it is for educational purposes only

We are then met with this page: feel free to bookmark it!

And now we can click on the settings button (as circled)

You can edit the name and describe your bot to make it easier to know where is everything

Scroll down and then set-up your user authentication settings by checking 'Read and write' on App Permissions and check 'Native App' on Type of App

Then, put your bot's Replit url on the App Info section

You can find the url by running your bot on Replit and clicking on 'New tab' on the right side of your screen

You can then copy the link from the new tab

Next, scroll up and click on 'Keys and tokens'

Make sure to write everything down somewhere: maybe in a txt file on your computer to not lose these!

You can first 'Regenerate' the API key and Secret aka your Consumer Key and Consumer Secret

And then, 'Generate' your Bearer Token and your Access Token and Access Token Secret

IMPORTANT: These are all private information: this is like a password for your bot: so don't share these anywhere!

Putting your 'Secrets' on Replit

This will be the key for your bot's code to reach your Twitter account!

On Replit: scroll down the 'Tools' section on the bottom-left of the screen (1) until you find the 'Secrets' section and click on that (2)

For each category: you can click on 'New Secret' on the upper-right of your screen

On the 'Key' section, write the name of the key that you're entering and on the 'Value' section, write the code that you got from your Twitter developer account

You will need to do this process 5 times and name the keys as follows:

consumer_key

consumer_secret

bearer_token

access_token

access_token_secret

Your twitter account and your bot's code are now connected to eachother!


Keep your bot running with Uptimerobot

You can't always leave the Replit page open on your computer 24/7: this is why we need an outside source to keep the bot running!

about me!