Inspiration
Hello MLH!
My Inspiration for building this application was...... Global Hack Week!
GHW in April was going to be one of the first MLH Event and I was super excited when I registered for it. In that excitement, I started to research and learn more about APIs. I am someone who is a very hands on learner so I thought it would be best to build something basic and simple that uses an API in it. To quench my excitement for Global Hack Week, I started to build this Command-Line Application a few days before Hack Week started.
What it does
My CLI application takes a base currency, a target currency and an amount from the user. It then uses that information to build a URL and fetch data from the API and then output the converted data. It also takes a positional arguments, which when requested, returns the current exchange rate between the respective currencies.
The first argument is the base currency, the second argument is the target currency, and the third argument is the amount that is to be converted. It also takes an optional argument that displays the current exchange rate.
How we built it
1) The first step, Planning: The first part included me understanding the different components, dividing them on the basis of how much I know about them, how much more I'll need to know about them and more such miscellaneous factors. I structured all these into steps that I can follow to build my application ranging from how much time a certain component would take me. Like for example: API's were a totally new thing, so they required me to put my maximum time on research and understanding and figuring out how it had to be done.
2) The API: I settled on which API to use and worked with it. In the beginning I had a separate file which stored my API key. It was a secret file, which is why I realized that it would not be the most user-friendly way for my application to work. So in the current version of my application, the user's are required to set their own API key from their environment variables. I did this by using Python's os module.
3)Parsing the Arguments: I used the argparse module to parse CLI arguments. The user provides the base currency, target currency, and the amount they want to convert. They can also choose to display the conversion rate.
4) Building the Query URL : I built the query URL using the base currency, target currency, amount, and the API key. You used the urllib.parse module to format the base and target currencies into URL format.
5) Fetching Data from the API : I created a request object for the built URL and initiated the HTTP request. I handled potential HTTP errors and read the server response.
7) Displaying the Information : Finally, you displayed the conversion information to the user. If the user chose to display the conversion rate, you included it in the output.
8) Main Function: In the main function, you called the functions you defined earlier in the following order: read_user_cli_args(), build_conversion_query(),get_conversion_data(), and display_information().
Challenges we ran into
In my first try for selecting an API, I acted a bit hastily out of excitement and chose an API that only supported one single base currency which was something I realized halfway into completing my application. I realized my mistake and switched to another API that was more suitable for this application.
The other challenge I ran into while building this application was that of building my URL and fetching data from it. For a painstakingly long time, I believed it was how I formatted my text, however, it was not that. This challenge taught me something very crucially important when using URLs and http commands. And it was that I needed to add a user-agent. Without this, it did not get authorization to fetch data from the URL. Now if I am to face a problem like this in the future, I'll know one of the many possible remedies to it!
Accomplishments that we're proud of
Learning to use and understand the basics of an API was my goal with this application. There are as always, more things to learn and understand of APIs but I did finally wrapped my had around what and how exactly REST Architecture APIs work.
I built my first Python application! It was command-line and I did know and understand some basics but this was my first complete project.
And the most important accomplishment of them all was that I had fun! Running into errors and not knowing what to write and code next was frustrating, but finding the solution to my errors felt like I won even without entering my project.
What's next for currency-converter
Further, I would like to build and turn it into something with a much more interactive interface which is much more intuitive and pretty to look at. My current aim with this project was to use an API and get an idea of how they're used in applications.
Built With
- exconvertapi
- gitpod
- python
Log in or sign up for Devpost to join the conversation.