DEV Community 👩‍💻👨‍💻

Cover image for What I learned after creating and sharing an interactive twitter bot and getting 1000's of replies
Ryan (he/him)
Ryan (he/him)

Posted on

What I learned after creating and sharing an interactive twitter bot and getting 1000's of replies

The Tweet that started it

So two days ago I tweeted for the 11th day in my #1ooDaysOfCode challenge. 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...


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 - 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

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

I woke up

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

Alt Text

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

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

The full code for this and other bots I've written can be found in my GitHub repo.
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! 🙏 🙏 🙏

Top comments (4)

hinasoftwareengineer profile image

Great work! Keep going 👏 👏 👏. I also wanted to start 100DaysOfCode. But I am confused in that in these 100Days I will only learn new concepts of any programming language or make projects or Both?

ryry_02 profile image
Ryan (he/him) Author

Thank you 😊🙏
I think it's completely up to you, do what you think will help you most 😊 I learn best by learning the basics/following tutorials, building a project from that and then getting feedback - so that's how I'm going to do the challenge!

tngeene profile image
Ted Ngeene

Hey, I saw your tweet. Great work man. I was one of the people who never got their picture drawn :(, probably during the time the bot had crashed. Is it working well now?

ryry_02 profile image
Ryan (he/him) Author

Thanks mate! Ah, sorry about that! :( yeah it's up and running again, doesn't seem to work 100% of the time but it's doing pretty well 😊

🌚 Friends don't let friends browse without dark mode.

Sorry, it's true.