What I learned after creating and sharing an interactive twitter bot and getting 1000's of replies
Tags: python, automation, 100daysofcode, twitter
Published: 2020-05-30 11:53:35

## The Tweet that started it


{% twitter 1266046173204398080 %}

So two days ago I tweeted for the 11th day in my [#1ooDaysOfCode challenge](https://www.100daysofcode.com/). I announced that anyone who replied to my tweet with the phrase "draw me" would have a Twitter bot I developed, reply to their tweet with a "hand-drawn" image of their profile picture. And it worked - to start with...

## Background

Two weeks ago I decided to take part in the #100DaysOfCode challenge. I am a Data Engineer (SQL and Java) by trade but rarely code in my spare time and have wanted to learn about Python for a long time but never really got round to it and have never been consistent. For the past two weeks, I have been writing Twitter bots in Python and learning as I go.

This post is about what learned from putting myself and my work out there on Twitter - not the code itself. That may come in a follow-up post if people want it, but if anyone wants to get started writing Twitter bots in Python I'd encourage you to start [here](https://realpython.com/twitter-bot-python-tweepy/) - this is where I started two weeks ago.

## A timeline of what happened

#### I sent the tweet
So I always code after my 9-5 job, after a few tweaks I deployed my bot and tweeted about it at 5.38 pm.

#### The first few minutes

Nothing much happened...

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/5u4bi3wc7k0ae17hf5ai.gif)

I had about 100 followers and not a lot happened straight away.

#### A few minutes later

A couple of friends tried it out and it worked - success!! I was really happy it worked as I found it quite hard to test locally beforehand.

#### I went for a walk and had dinner

So, happy with my success, I went for my normal evening walk and had dinner when I got home. I then checked my phone and had over 200 replies to my tweet - oops, wasn't expecting that! 

But everything seemed to be working and I was happy with it, so...

#### I watched some tv and went to bed

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/43l9s0zr12r8hg2nlloh.gif)

#### I woke up
I woke up to over a 1000 replies and a broken bot. 

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/oi66ygo1zad9nr0ro6da.gif)

Maybe there were too many replies to process, maybe I exhausted my free hosting software's CPU or maybe - **it was this one** - one individual decided to have a profile picture that wasn't a rectangle...

#### Patch it QUICK!!!

So it was totally my fault the code broke. I had no exception handling around the image shape, I thought it wouldn't be an issue - how naive I was.

A quick commit later, a redeploy and everything worked again! Phew!

## So what did I learn?

#### Lesson 1: Expect the unexpected
I had some exception handling in my code to begin with but not everywhere. I was not expecting the error that occurred but that doesn't mean I shouldn't have in some way accounted for it in the code.

I fixed the issue simply by wrapping a large chunk of code in a `try` with an `except` at the end (not pretty I know, but it did the job). If the bot failed on any user it simply skipped them and moved to the next. Not the ideal solution but when processing thousands of requests, better to miss a few than fall over and miss hundreds.

#### Lesson 2: Embrace failure and learn from it
I've often read articles about failing in the public eye and being better for it, I always thought "good for you, but I'm ok thanks". I've changed my mind.

If this had been something I was working on at home by myself after everything crashed I probably would have left it and walked away. A thousand people on twitter telling you something doesn't work? Better fix it fast! And being forced to fix it fast I learned more about debugging, problem-solving and deploying a hot-fix than I would have otherwise.


#### Lesson 3: Not everyone will respond positively
The bot went down and so not everyone got their replies and drawings. Some people found it funny, said they didn't mind and they hoped I fixed it. Others sent me DMs saying my work was stupid and useless. Thankfully this was a tiny minority of people. Try to not let the small minority ruin something positive for you.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/1m5mvxicir4j1nv9sa7w.gif)

#### Lesson 4: Build projects
Following tutorials is great and that's how I learn the basics... but you need to build upon the basics, tinker, play around and build projects you're interested in. If you just follow tutorials, you've followed instructions successfully. If you build on that and add to it, you've created something yourself. Which is more interesting and motivating?

#### Lesson 5: Share your work
Not everything went according to plan - obviously. But I'm so happy and grateful for what happened and how the tech twitter community responded to my little experiment. The feedback and engagement I received is so motivating and I just want to build more now!

The majority of the community on Twitter is really helpful and encouraging. I've made friends there through sharing my work, appreciating others work and just keeping each other motivated.

I have learned more by putting my work on display for 2 days than I have in the last 2 years of my 9-5. I'd encourage you to do the same. Share your work, get feedback, and grow! You might even inspire others in the process!

So what are you waiting for? Share your work with the community

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/km1kol340sf1s13b2k0v.gif)




##### The full code for this and other bots I've written can be found in my [GitHub repo](https://github.com/ryan-joseph-dev/twitter-bots).

##### The bot is currently still live, so please feel free to give it a try, it won't be up forever and may be moved to its own twitter account in future. Thank you so much for reading, as always any and all feedback is hugely appreciated! 🙏 🙏 🙏