/TrendyLocations

Trendy Locations is a daily Twitterbot that gathers Twitter's top trending terms and generates a what3words location and uses the associated coordinates to tweet satellite imagery from Google Maps of that place on Earth.

Primary LanguageJavaScript

Trendy Locations

Trendy Locations (@trendylocations) is a twitterbot that gathers Twitter's top 50 trending terms in the US using the Twitter API and finds a three-word combination of those terms which form a known what3words (what3words.com) address on Earth.

How it works

The top 50 trending terms on Twitter throughout the United States (the API requires a single specified region) are gathered and put into a complex JSON-like object that needs to be explored before I can ever reach the individual elements. Once I traverse the data structure I filter all 50 through a comprehensive list of English words (about 10,000 words) such that words that contain non-alphabetical numbers or characters get removed from the resulting list, and only words that are likely to return an address on what3words are kept and used, 10 words are all I need.

This 'words' array is then put into a method that returns a new array which consists of 120 permutations of possible 3-subsets (subset arrays of size 3) generated with my 10 words. I explain this slightly better in the code comments. I join these subset array elements with a period and generate a string. Like so: [word1, word9, word4] => "word1.word9.word4". I am left with an array of 120 of these what3words-like string addresses.

I pick one of these strings at random to submit to the what3words API. The API will try to return the corresponding location on Earth but may fail. If it fails it will perform logic that turns my string into a different string with words which are considered "similar" or "related" and have a definite what3words location. Their API defines what that means.

Using the location metadata gathered from the what3words API as (latitude, longitude) coordinates, Google Maps Static API inputs those values as parameters of its Static API link and returns a .png image of satellite photography at those coordinates. This photo is saved locally at runtime so that it can be later be used to decorate a Twitter post, which was uploaded using Twitter API v2. The tweet message consists of the location gathered from the what3words API at runtime, such as the nearest recognizable region, town, or city.

I specify certain parameters and the Maps Static API generates the photo and I generate the tweet message body using the data from what3words. Then I post the tweet to Twitter for the world to see! Check it out here.

The Twitterbot has not been deployed on Heroku but I was planning on getting it uploaded so that it could run automatically, once a day. Instead, for now, I instantiate each build on my computer.

Author

Trendy Locations was created by me, Jorge Aquino, for my LMC 2700 class. 📝 My Resume is viewable on my site aquino.design.

Inspiration and Context

Some initial rudimetary twitterbot logic was inspired by AndrewKeymolen's EverydayManga repository, the logic was specifically regarding Twitter API media attachment and collection. StackOverflow was used throughout to troubleshoot and some lines code, specifically those involed with creating subset arrays recursively, were implemented based on user responses on the site. The logic of the bot's location gathering and just about everything else was entirely my work, though.

Inspiration for the bot was found on @sillygwailo's ThoughtStreams.io blog post titled "twitter bot ideas".