#2 Navigating the Python ocean

In the previous post, I finished it with an example of how to GET the data from an API endpoint and print some result coming from the data. In this post, I will unfold the project I am working on and why APIs are important for it.

The APIs and the GET request.

Today’s websites and online applications are reachable using their API (Application Program Interface) and APIs are build, generally in JSON format. Like HTML is the language to build websites for humans, JSON is the language to build websites for computers. The cool part of Python is the libraries out of the box ready to connect and process APIs and its data. One of the goals of my project is working with the data coming from one API, take some pieces from it and use it to create the next request in a second API.

For example, https://openweathermap.org/ will provide the coordinates (Latitude and Longitude) that later I can use with https://foursquare.com/ and determine some places to eat, have a coffee or an iced tea. By then I will know the temperature and I can choose whether I want something hot or cold. Getting the data from the first API, store it in a list, and then using that data for other purposes took me quite a long time (days and nights). But it is paying off since this is allowing me to understand the way how a programming language like Python works and manage data.

At this point, one of the things that my mentor recommended was breaking the code in small pieces and build a function from each piece. The cool part of doing that enable me to understand the meaning of functions itself and recycling the code by calling the function instead re-writing it.

What I have learned so far?

Reading and using examples codes available in the official documentation of Python and in each library helps but in my case gave me 10% to 20% of understanding what I just read and did.

Reading different approach about the same topic in books gave me another 10% to 20% of understanding.

Having a dedicated space with a whiteboard where I can add notes and example code add another 10%.

Identify the logic or code you are repeating, then find the way to build a function out of it and call it every time you need it. This added another 20%

Constantly re-read the code and find the way to improve it or include pieces like documentation or comments that could help you to understand what is the purpose of the code, and what is expecting. The documentation is like the terminator from the future, but in this case, it will save your time.

What is next in the project?

Add a web interface and storing meals data. Here the goal is having some visual interface for an easy request and testing. The stored data will be used for analysis on calories and nutrition from each item by day, week, month. This information can be obtained with another API :)