Building aTwitter Bot (my 2nd) for Native Plants of Hawaii and Puerto Rico — A Reflection

Another day, another Twitter bot.



A little over a month ago, I decided it would be fun to do a new project to practice Python, by using an old project format I’d experimented with a few years ago (a Twitter bot) to share data on a subject I’ve become quite passionate about in the past few years (what flora is native to what parts of the world). After discarding a few ideas, I settled on making 2 different bots — one that tweets flora native to Hawaii, and one that tweets flora native to Puerto Rico. Both of the islands are overseas territories (many would say colonies) of the United States, so I had their botanical datasets already handy, and both are hotspots of endemic biodiversity, which is to say native species found nowhere else on the planet.

Ultimately, my primary goal of creating these bots was to produce yet another tool that encourages folks to plant and grow flora that is native to whatever place they live (truly, it’s a killer heuristic to guide your cultivation of plants — whether that’s a single potted plant on your stoop or a vast forested estate). But my secondary goal was to practice Python, and it yielded 2 main takeaways. These learnings are probably obvious to folks more seasoned than I am in this kind of thing (making computers do what you want), but it felt worth detailing them nonetheless, in case any other learners stumble across this little writing:

1. Did I get better at Python, or did I just have better data sources and pre-existing code to work from?

The last Twitter bot that I wrote (an account that Tweets a fable by Aesop every day) was — looking over it today — garbage. It works, but barely. I wrote it at a time when I knew hardly any Python, and was hoping that sheer force of will and relentless Googling would make something that worked. It ended up working, but only in the sense that a room of monkeys jumping on typewriters for a billion years will eventually replicate the works of Shakespeare or Sun Tzu or (most topically) Aesop. I don’t even like to look at the code anymore — it’s shameful. And while the newer native botanical script isn’t great, it’s a lot neater than its fabulist predecessor. So what changed?

The obvious answer is that I got better at writing Python, but that’s not the whole story. A different part of it was that I just had better data sources and means to access them, provided by earlier code that I wrote, which is still running away in the background from a year ago.

For example: the Hawaii/PR Twitter bots use environmental datasets, refreshed monthly, from one of my Google Cloud Storage buckets. But even though I wrote the bots in Python, these datasets aren’t generated by Python. They’re generated by an older set of R scripts that run monthly from a Google Cloud VM to scrape various USDA plant/NOAA weather/NCSS soil data sources, fix up the data in a particular way, and upload it to that Storage bucket. And when I wrote these scripts, I had no intention of using them to provide data for Twitter bots. In fact, I originally wrote the code so that I could feed it into the US-focused native plant finder web app that I wrote in Shiny. But even when I was writing the code, I had the feeling that it could be useful for other applications besides the initial amateur web app I went on to create. All to say —even when you’re learning a new language (in my case, Python), you can still benefit from the code/data that you wrote/produced in your old language of choice (in my case, R). Just make sure the old code is good enough to keep working most of the time.

It’s possible there’s already a well-established term for that concept of compounding benefits from your own personal body of ‘digital infrastructure’ (corny term, but best I can do), in the same way that computer people like to talk about ‘tech debt’? If so, I’d love to learn it. But what struck me about this realization, enough to write about it, is just how fine the line is between A. re-using the code you’ve already written or B. using your improved skills to just write better code. I ultimately had to do both, which leads to Learning Number 2:

1. No, I actually got better at writing Python.

I can ultimately attribute only 40% of the relative ease of constructing this Twitter bot to the quick access to data provided by code I’d already written. A solid 60% was just because I actually am better at the language (though still pretty garbage). Turns out that practicing a language for 2 years and becoming halfway proficient in a few key packages (pandas, requests, BeautifulSoup) can yield some improvement.

In summary: these learnings are clearly simplistic, but they have been useful revelations nonetheless, and hopefully well-earned in the service of encouraging more folks to plant native.




he/him. having fun with my friends in cyberspace

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

AKS Primality Test (Primes is in P)

Understanding “Git”

Interact with TouchOSC MK1 #2: Send data back to TouchOSC MK1- Tutorial in TouchDesigner

Deep Learning Tools to Know in 2022

Gambit Testnet Begins

Initiator Creator — My second attempt to create a community for side hustlers.

Seeking Concinnity in Coding Conventions

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Liam A. Trotzuk

Liam A. Trotzuk

he/him. having fun with my friends in cyberspace

More from Medium

The Declaration of Independence was Illegal…and That’s Okay!

Sonora Desert Museum, Arizona — Natural history and botanical garden

Do You Want To Learn About North American Tundra Swans?

Making Peace With The River

Muddy water running under wooden bridge across wide river that has recently flooded. Trees line the river with clouds swirling in the blue sky.