Skip to content

Commit

Permalink
Merge pull request #14 from quantmind/master
Browse files Browse the repository at this point in the history
1.1.0
  • Loading branch information
lsbardel authored Aug 4, 2019
2 parents 245cf92 + c86cd9c commit f901334
Show file tree
Hide file tree
Showing 22 changed files with 948 additions and 480 deletions.
16 changes: 3 additions & 13 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
version: 2
jobs:
test35:
docker:
- image: circleci/python:3.5
steps:
- checkout
- run:
name: install
command: sudo ./dev/install.sh
- run:
name: test
command: pytest
test36:
docker:
- image: circleci/python:3.6
Expand All @@ -33,6 +22,9 @@ jobs:
- run:
name: flake8
command: flake8
- run:
name: black
command: make black
- run:
name: test
command: pytest --cov
Expand Down Expand Up @@ -65,12 +57,10 @@ workflows:
build-deploy:
jobs:
- tests
- test35
- test36
- deploy-release:
requires:
- tests
- test35
- test36
filters:
branches:
Expand Down
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"python.pythonPath": "venv/bin/python"
}
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ clean: ## remove python cache files

version: ## dipsplay software version
@python3 -c "import ccy; print(ccy.__version__)"


black: ## check black formatting
black --check ccy tests
5 changes: 2 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ join and add more.

:Package: |license| |pyversions| |status| |downloads|
:CI: |master-build| |coverage-master|
:Documentation: http://pythonhosted.org/ccy/
:Dowloads: http://pypi.python.org/pypi/ccy
:Source: https://github.com/lsbardel/ccy
:Dowloads: https://pypi.org/project/ccy/
:Source: https://github.com/quantmind/ccy

.. |pyversions| image:: https://img.shields.io/pypi/pyversions/ccy.svg
:target: https://pypi.org/project/ccy/
Expand Down
91 changes: 62 additions & 29 deletions ccy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,41 +1,74 @@
"""Python currencies"""

__version__ = '1.0.0'
__version__ = "1.1.0"


from .core.currency import (
currency, currencydb, ccypair, currency_pair,
dump_currency_table
)
from .core.country import (
country, countryccy, set_new_country,
countries, set_country_map, country_map,
CountryError, eurozone, print_eurozone
CountryError,
countries,
country,
country_map,
countryccy,
eurozone,
print_eurozone,
set_country_map,
set_new_country,
)
from .core.daycounter import getdc, ActActYears, alldc
from .core.currency import (
ccypair,
currency,
currency_pair,
currencydb,
dump_currency_table,
)
from .core.daycounter import ActActYears, alldc, getdc
from .dates.converters import (
todate, date2timestamp, timestamp2date, yyyymmdd2date,
date2yyyymmdd, juldate2date, date2juldate, date_from_string,
jstimestamp
date2juldate,
date2timestamp,
date2yyyymmdd,
date_from_string,
jstimestamp,
juldate2date,
timestamp2date,
todate,
yyyymmdd2date,
)
from .dates.futures import future_date_to_code, future_month_dict
from .dates.period import period, Period

from .dates.period import Period, period

__all__ = [
'currency', 'currencydb', 'ccypair', 'currency_pair',
'dump_currency_table',
"currency",
"currencydb",
"ccypair",
"currency_pair",
"dump_currency_table",
#
'getdc', 'ActActYears', 'alldc',
"getdc",
"ActActYears",
"alldc",
#
'country', 'countryccy', 'set_new_country',
'countries', 'set_country_map', 'country_map',
'CountryError', 'eurozone', 'print_eurozone',
'future_date_to_code', 'future_month_dict',
'period', 'Period',
'todate', 'date2timestamp', 'timestamp2date',
'yyyymmdd2date', 'date2yyyymmdd', 'juldate2date',
'date2juldate', 'date_from_string', 'jstimestamp'
"country",
"countryccy",
"set_new_country",
"countries",
"set_country_map",
"country_map",
"CountryError",
"eurozone",
"print_eurozone",
"future_date_to_code",
"future_month_dict",
"period",
"Period",
"todate",
"date2timestamp",
"timestamp2date",
"yyyymmdd2date",
"date2yyyymmdd",
"juldate2date",
"date2juldate",
"date_from_string",
"jstimestamp",
]


Expand All @@ -45,22 +78,22 @@ def cross(code):


def crossover(code):
return currency(code).as_cross('/')
return currency(code).as_cross("/")


def all():
return currencydb().keys()


def g7():
return ['EUR', 'GBP', 'USD', 'CAD']
return ["EUR", "GBP", "USD", "CAD"]


def g10():
return g7() + ['CHF', 'SEK', 'JPY']
return g7() + ["CHF", "SEK", "JPY"]


def g10m():
"""modified g10 = G10 + AUD, NZD, NOK
"""
return g10() + ['AUD', 'NZD', 'NOK']
return g10() + ["AUD", "NZD", "NOK"]
40 changes: 21 additions & 19 deletions ccy/core/country.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
# using ISO 3166-1 alpha-2 country codes
# see http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
#
eurozone = tuple(('AT BE CY DE EE ES FI FR GR IE IT LU LV LT MT '
'NL PT SI SK').split(' '))
eurozone = tuple(
("AT BE CY DE EE ES FI FR GR IE IT LU LV LT MT " "NL PT SI SK").split(" ")
)


def print_eurozone():
Expand All @@ -29,7 +30,7 @@ class CountryError(Exception):
def country(code):
cdb = countries()
code = country_map(code)
return cdb.get(code, '')
return cdb.get(code, "")


def countryccy(code):
Expand All @@ -39,15 +40,16 @@ def countryccy(code):


def countries():
'''
"""
get country dictionar from pytz and add some extra.
'''
"""
global _countries
if not _countries:
v = {}
_countries = v
try:
from pytz import country_names

for k, n in country_names.items():
v[k.upper()] = n
except Exception:
Expand All @@ -56,27 +58,27 @@ def countries():


def countryccys():
'''
"""
Create a dictionary with keys given by countries ISO codes and values
given by their currencies
'''
"""
global _country_ccys
if not _country_ccys:
v = {}
_country_ccys = v
ccys = currencydb()
for c in eurozone:
v[c] = 'EUR'
v[c] = "EUR"
for c in ccys.values():
if c.default_country:
v[c.default_country] = c.code
return _country_ccys


def set_country_map(cfrom, cto, name=None, replace=True):
'''
"""
Set a mapping between a country code to another code
'''
"""
global _country_maps
cdb = countries()
cfrom = str(cfrom).upper()
Expand All @@ -86,7 +88,7 @@ def set_country_map(cfrom, cto, name=None, replace=True):
c = name
cto = str(cto).upper()
if cto in cdb:
raise CountryError('Country %s already in database' % cto)
raise CountryError("Country %s already in database" % cto)
cdb[cto] = c
_country_maps[cfrom] = cto
ccys = currencydb()
Expand All @@ -101,34 +103,34 @@ def set_country_map(cfrom, cto, name=None, replace=True):
cdb.pop(cfrom)
cccys.pop(cfrom)
else:
raise CountryError('Country %s not in database' % c)
raise CountryError("Country %s not in database" % c)


def set_new_country(code, ccy, name):
'''
"""
Add new country code to database
'''
"""
code = str(code).upper()
cdb = countries()
if code in cdb:
raise CountryError('Country %s already in database' % code)
raise CountryError("Country %s already in database" % code)
ccys = currencydb()
ccy = str(ccy).upper()
if ccy not in ccys:
raise CountryError('Currency %s not in database' % ccy)
raise CountryError("Currency %s not in database" % ccy)
cdb[code] = str(name)
cccys = countryccys()
cccys[code] = ccy


def country_map(code):
'''
"""
Country mapping
'''
"""
code = str(code).upper()
global _country_maps
return _country_maps.get(code, code)


# Add eurozone to list of Countries
set_new_country('EU', 'EUR', 'Eurozone')
set_new_country("EU", "EUR", "Eurozone")
Loading

0 comments on commit f901334

Please sign in to comment.