Bash | Consuming API exchange
Posted
Pixabay
"Happiness is only real when shared."
Christopher McCandless
Shell Currency Exchange
This shell script program aims to be a helpful tool in the daily basis of CLI users. This simple application provides real time currency information through API requisitions.
Requirements
This project works with http requisitions to an external API for each time you call the program. You must generate your own key to be able to realize requisitions.
Inside currency.sh
you can find the global variable API_KEY
.
declare -r API_KEY="<MyKey>"
Paste the generated key into the quotes.
Also, make sure you have curl and bc properly installed. This application works through those packages. You can easily try the following commands in your shell to install the packages through =apt=:
curl --version || apt-get install curl= and =bc --version >/dev/null || apt-get install
How to Use it
Open a terminal or command prompt, paste the following command to it:
git clone https://github.com/RaphaelSilv/shell-currency.git
Inside =shell-currency= you can find =currency.sh= make sure to provide execution rights through chmod command for it.
The last step is to add the absolute path to the file above to your environment
variables. If you use zsh
or bash
open your terminal, go to home and open =.bashrc or .zrsch=
with you favorite text editor and create an alias as the following:
alias <MyAlias>=<path>currency.sh
Close the terminal and open it again.
Now the try following command: curr -f usd -t brl -a 1
should produce an output similarly like so:
===================================
date: Sat, 25 Jan 2020 17:36:31 GMT
1 USD = 4.181404 BRL
===================================
Of course the value may change according to economical determinants.
Help
The API used support the following currencies:
Each country has one 3 digits character used for requisitions. For instance:
brl, usd, btc
correspond respectively to American Dollar, Brazilian reais and
Bitcoin
You can have more info in curr -h
Clone us on github
RaphaelSilv /shell-currency-exchange
API’S sample codes
This project was added to the API’s sample codes official documentation. Over there you can find other usage examples that would fit better your needs or you can create an usage example that don’t already exists and help the community.
License
You can use this source code however you like. If necessary, please refer to the API’s Terms of Service. If you appreciated the services provided, consider buying the API maintainer a coffee as he is the one that has costs with domain, hosting, bandwidth and, of course, with coffee.