Ranking capitals by the number of Starbucks using Python and Google Maps API

Artem Rys
Artem Rys
Jul 22, 2019 · 2 min read
Starbucks logo
Starbucks logo
Photo by Khadeeja Yasser on Unsplash

Recently being in Budapest (great city by the way) I saw lots of Starbucks coffee shops and decided to write a small script that will rank capitals by the number of Starbucks there.

I am not pretending to get the most accurate results, it is just an example. So, please don’t use it make some serious business decisions :)

We will use Google Places API and a local copy of a bit reworked list of capitals’ coordinates from here.

The full code is available here.

First of all, let me say that Google Places API has a serious limitation of returning maximum 60 results for one search. That’s why we need to be a bit tricky. We will request it several times with different coordinates and then count a number of unique places that we got.

Probably not the best solution but it at least simple and returns more than 60 places. If you need more precise results there are lots of Google Places API wrappers around the web.

To run it by yourself you need to get a key. Don’t be afraid about money, I spent 0$ while I was testing my code.

Small hack to get near coordinates.

Using this function we can create a class that searches Starbucks in the different parts of the world. get_starbucks is just a function that makes a call to Google Places API.

Searches Google Maps for the Starbucks cafes

Fact: 117 out of 240 capitals don’t have Starbucks at all.

Top 30 capitals by the number of Starbucks there:

Top 30 capitals sorted by the number of Starbucks cafes. Full list available here.


Thanks for the attention to the topic, feel free to leave your questions in the comments for discussion.

python4you

Articles about general Python, best practices and interviews.

Artem Rys

Written by

Artem Rys

Senior Python Developer @ EPAM Poland

python4you

Articles about general Python, best practices and interviews.

More From Medium

More from python4you

More from python4you

5 Scraping Tips

198

More on Tech from python4you

More on Python from python4you

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade