Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
gokomer committed Jun 4, 2019
0 parents commit 931ea48
Show file tree
Hide file tree
Showing 7 changed files with 154 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.vscode/
build/
dist/
exrates.egg-info/
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 Ömer GÖK

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Exrates

Exrates is a simple Python application to get exchange rates from https://exchangeratesapi.io/

## Usage

```
usage: Exrates [-h] [-b BASE] [--version] symbols
positional arguments:
symbols Currencies seperated by comma
optional arguments:
-h, --help show this help message and exit
-b BASE, --base BASE Base currency (default: EUR)
--version show program's version number and exit
```
## Examples

Base currency is EUR

```
# exrates try
Base currency is: EUR
TRY 6.5815
```

You can change base currency with -b option

```
# exrates try -b usd
Base currency is: USD
TRY 5.8842199374
```

You can use multiple currencies by seperating them with a comma

```
# exrates try,cad
Base currency is: EUR
CAD 1.5098
TRY 6.5815
```
1 change: 1 addition & 0 deletions exrates/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
name = "exrates"
8 changes: 8 additions & 0 deletions exrates/__version__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
__title__ = 'exrates'
__description__ = 'Simple exchange rates'
__url__ = 'http://github'
__version__ = '1.0'
__author__ = 'Ömer GÖK'
__author_email__ = '[email protected]'
__license__ = 'MIT'
__copyright__ = 'Copyright 2019 Ömer GÖK'
42 changes: 42 additions & 0 deletions exrates/exrates
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env python3
import requests
import argparse
from requests.exceptions import HTTPError
from requests.exceptions import Timeout


__version__ = "1.0"
BASE_URL = "https://api.exchangeratesapi.io/"

def getParams():
parser = argparse.ArgumentParser(formatter_class = argparse.ArgumentDefaultsHelpFormatter, prog='Exrates')
parser.add_argument("symbols",
type = str,
help = "Currencies seperated by comma")
parser.add_argument("-b", "--base",
dest='base',
type = str,
default = "EUR",
help = "Base currency")
parser.add_argument('--version', action='version',
version=f'{parser.prog} {__version__}')
results = parser.parse_args()
params = [('base', f'{results.base.upper()}'), ('symbols', f'{results.symbols.upper()}')]
return params

def getRates(params):
try:
response = requests.get(f"{BASE_URL}" + "latest", params=params(), timeout=5)
response.raise_for_status()
except Timeout:
print('The request timed out')
except HTTPError as http_err:
print(f'HTTP error occurred: {http_err}')
else:
formatted_results = response.json()
print(f"Base currency is: {formatted_results['base']}")
for k,v in formatted_results['rates'].items():
print(k,v)

if __name__ == "__main__":
getRates(getParams)
35 changes: 35 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env python
import os
import setuptools


here = os.path.abspath(os.path.dirname(__file__))

about = {}
#with open(os.path.join(here, 'exrates', '__version__.py'), 'r', 'utf-8') as f:
with open(f"{os.path.abspath(os.path.dirname(__file__))}/exrates/__version__.py") as f:
exec(f.read(), about)

with open('README.md') as f:
readme = f.read()

setuptools.setup(
name=about['__title__'],
version=about['__version__'],
author=about['__author__'],
author_email=about['__author_email__'],
description=about['__description__'],
long_description=readme,
long_description_content_type="text/markdown",
url=about['__url__'],
license=about['__license__'],
packages=setuptools.find_packages(),
python_requires='>=3',
install_requires=['requests'],
scripts=['exrates/exrates'],
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
],
)

0 comments on commit 931ea48

Please sign in to comment.