Giter Site home page Giter Site logo

snifhex / currencyconverter Goto Github PK

View Code? Open in Web Editor NEW
8.0 2.0 9.0 24 KB

Currency Converter in python using Rates API.

License: MIT License

Python 96.02% Dockerfile 3.98%
hacktoberfest hacktoberfest2019 contributors prs github digitalocean prs-welcome dev opensource

currencyconverter's Introduction

currencyConverter

Command line currency converter.

Under the hood, conversion rates are obtained from this API: https://api.ratesapi.io

How to install

(optionally), create a virtualenv:

virtualenv ~/.venvs/currencyconverter
source ~/.venvs/currencyconverter/bin/activate

Install dependencies:

pip install requests

How to use

Simply launch the main python script and follow on screen instructions:

python converter.py 

E.g.:

python converter.py 
[*] Enter amount you want to convert > 42.42
[*] Enter base currency code you are converting from > eur
[*] Enter target currency code you are converting to > usd
42.42 EUR = 47.20 USD  (date: latest)

Or get amount converted directly with optional arguments

python converter.py -a 42.42 -b EUR -t USD
42.42 EUR = 47.20 USD  (date: latest)

This way it converts amount (45) from base currency (EUR) to target currency (USD).

If you only need amount in return (e.g. command used in pipe), use -s flag:

python converter.py -a 45 -b EUR -t USD -d 2018-01-01 -s
53.97

If any argument is missing or is invalid the wizard is launched.

./converter.py -a 42.42 -b EUR -t USD -d 2019-01-32
Incorrect value "2019-01-32": unconverted data remains: 2, try again...
[*] Enter date from which you want conversion rates, in format yyyy-mm-dd or string "latest" > 2019-01-23
42.42 EUR = 48.22 USD  (date: 2019-01-23)

You can also get help with

python converter.py -h
usage: converter.py [-h] [-a AMOUNT] [-b BASE] [-t TARGET] [-d DATE] [-s]

Currency converter tool

optional arguments:
  -h, --help           show this help message and exit
  -a AMOUNT            Amount you want to convert
  -b BASE              Base currency code you are converting from
  -t TARGET            Target currency code you are converting to
  -d DATE              Date from which you want conversion rates, in format
                       YYYY-MM-DD or string "latest" (default: latest)
  -s, --simple-output  If present, only converted amount is returned

How to use as a module in code

Install the package into your environment by doing:

pip install .

Example usage in your code:

>>> import converter
>>> converter.convert(42.42, 'usd', 'hrk', '2012-12-24')
Decimal('242.11')
>>> converter.convert(42.42, 'usd', 'hrk', '2012-12-24', decimal_precision=6)
Decimal('242.106582')
>>> converter.get_rates('USD')
{'GBP': 0.8110483651, 'HKD': 7.8421532016, 'IDR': 14146.4523180618, 'ILS': 3.4842881865, 
'DKK': 6.8008015302, 'INR': 70.9003552236, 'CHF': 0.9939885235, 'MXN': 19.5907641862, 
'CZK': 23.4456690045, 'SGD': 1.3789051826, 'THB': 30.455414883, 'HRK': 6.7597231078, 
# [...]
'USD': 1.0, 'AUD': 1.4798251207, 'HUF': 303.0877129065, 'SEK': 9.8465251844}

Run in Docker

Build image:

docker build -t currency_converter .

Run currency_converter:

docker run --rm -it currency_converter
[wizard questionare...]

or

docker run --rm -it currency_converter bash -c "./converter.py -a 45 -b USD -t GBP"
45 USD = 35.09 GBP  (date: latest)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.