Randomize your Twitter avatar

September 28, 2020

By Phil Cryer

Randomize your Twitter avatar from the command line

I'm pretty active on Twitter, and I wanted a way to change my Twitter avatar, to a randomly 'glitched' out version, on a set time (say hourly). I figured out a way to do this using Python, Twitter's API, and some random glitch services online. This method requires that you manually glitch the images you want, drop them in a directory, create a new Twitter App to get permissions to change your avatar, then install and use Tweepy to do the heavy lifting, all called by cron. I called the project randota = randomize twitter avatar = randomize your Twitter avatar from the commandline.

Follow the steps to do this for your own Twitter avatar.

Me
Glitched 1
Glitched 2
Glitched 3

Install

With all of my work, I'll assume you're comfortable playing around on a Linux system, and have git installed, if not you should be, it's endless amounts of fun! (Disclaimer: it may not be fun for you, no refunds)

Get the code

Clone the git repo and start to configure your environment

git clone https://github.com/philcryer/randota.git
cd randota
rm -rf img/*
cp config.json.dist config.json

Create a Twitter app

The first step you should take is to create a new Twitter App so you can get permissions to update your user's avatar. While there are many howtos out there, this one is complete and should get you going; How to create a Twitter application

Once you get to step "8. Make a note of your OAuth Settings", be sure and save:

  • Consumer Key
  • Consumer secret
  • Access token
  • Access token secret

Then define each of these values in your newly created config.json file:

{
    "consumer_key":        "<enter value here>",
    "consumer_secret":     "<enter value here>",
    "access_token":        "<enter value here>",
    "access_token_secret": "<enter value here>"
}

and save that.

Glitch your avatar

To glitch your avatar, play on here, otherwise if you just want to use standard avatars and rotate between them, jump to the next section

  • save your avatar locally
  • hit jpg-glitch, upload your avatar, glitch it as much as you want, or just choose the 'random' option
  • save the file into a directory /img
  • repeat as many times as you'd like to increase your randomness

TODO: I'd like to have an automated way to do this, maybe using some ImageMagik commands, that way we could have the script glitch the original on the fly and really get randomized images! Of course one strange blip and the images are unrecognizable to the original, but hey, that's random

Install requirements

sudo python -m pip install -r requirements.txt

Run it

python randota.py

View the hilarity on Twitter.com/<your_username>

Automate it

Add a new line to your user's crontab, fill out the path to where your code is

0 * * * *    python ${HOME}/code/randota/randota.py &gt;/dev/null 2&gt;&amp;1

What's next?

So when I started this I wanted it to just randomize my avatar for some variety and for fun, but what else could we do? Obviously it could be more active, for example, your hockey team wins, maybe it puts up an icon of your team (much like the Cub's W flag). Maybe it shows an umbrella if it's raining, maybe something related to the news of the day. Maybe you're a different Pokemon everyday. I've also thought of having it change the displayed name in Twitter, again, responding to some action in the "real world" that changes something on your account. Think of something cooler to do than just this and please fork, make a PR, or share your thoughts. Thanks!

This article was originally posted on Phil's blog.


This work by Phil Cryer is licensed under Creative Commons Attribution 4.0 International (CC BY 4.0).