Ryan Joseph 💻😺@ryanjosephdevDay 1⃣1⃣ of #100DaysOfCode
If you'd like my twitter bot to draw your profile picture, reply "draw me" to this tweet - hopefully I will reply within 1 minute with a drawn copy of your profile pic! 🤞
Have fun! 😊
...I'll nervously monitor my cpu 😆 @BriceFriha16:38 PM - 28 May 2020
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.
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.
Nothing much happened...
I had about 100 followers and not a lot happened straight away.
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.
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 woke up to over a 1000 replies and a broken bot.
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...
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!
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.
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.
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.
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?
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