Yet another refactoring finished. Version is still 1.0.0 because it was never released before.
This commit is contained in:
parent
33ec32cb18
commit
bab9fda3fb
41
README.md
41
README.md
@ -4,8 +4,8 @@ Every time you put coins in or take them out of your piggy bank, write here down
|
|||||||
how much did you put or take. So you won't have to spend time counting them when
|
how much did you put or take. So you won't have to spend time counting them when
|
||||||
you decide to take them all out.
|
you decide to take them all out.
|
||||||
|
|
||||||
Yes, only coins, no banknots. Well, you actually can easily add support for
|
Yes, only coins, no banknots. Well, you actually can easily add them, but table
|
||||||
banknots, but table will become indeed wide.
|
will become indeed wide.
|
||||||
|
|
||||||
# Usage
|
# Usage
|
||||||
|
|
||||||
@ -15,13 +15,9 @@ banknots, but table will become indeed wide.
|
|||||||
Common options:
|
Common options:
|
||||||
|
|
||||||
- `-h,--help` — print this help;
|
- `-h,--help` — print this help;
|
||||||
|
|
||||||
- `-v,--version` — print program version;
|
- `-v,--version` — print program version;
|
||||||
|
|
||||||
- `-L,--list-currencies` — list supported currencies and a default one;
|
- `-L,--list-currencies` — list supported currencies and a default one;
|
||||||
|
|
||||||
- `--set-default-currency` — set currency that'll be used as a default;
|
|
||||||
|
|
||||||
## Brief usage with examples
|
## Brief usage with examples
|
||||||
|
|
||||||
### Put coins in
|
### Put coins in
|
||||||
@ -58,11 +54,11 @@ piggybank [-r | --reversed] COINS in FILE [of CURRENCY]
|
|||||||
```
|
```
|
||||||
|
|
||||||
`--reversed` flag reverses the order of coins. By default they come from least
|
`--reversed` flag reverses the order of coins. By default they come from least
|
||||||
significant face value to the most significant one and as stated above being
|
significant face value to the most significant one and being complemented from
|
||||||
complemented from left so a set shorter than number of coins in a currency,
|
left so a set shorter than number of coins in a currency, e.g. 5 8 4 will be
|
||||||
e.g. 5 8 4 will be interpreted as 0 0 0 5 8 4. And this flag will make it
|
interpreted as 0 0 0 5 8 4. And this flag will make it to be interpreted
|
||||||
to be interpreted as 5 8 4 0 0 0. It is convenient if you want to add only
|
as 5 8 4 0 0 0. It is convenient if you want to add only coins of low face
|
||||||
coins of low face value (e.g. cents).
|
value (e.g. cents).
|
||||||
|
|
||||||
`COINS` is a set of coins' counts separated with space or comma character. For
|
`COINS` is a set of coins' counts separated with space or comma character. For
|
||||||
example: 0 5 0 4 6 7. By default trailing zeroes will be added from the left.
|
example: 0 5 0 4 6 7. By default trailing zeroes will be added from the left.
|
||||||
@ -118,23 +114,24 @@ piggybank show example.pb with t
|
|||||||
|
|
||||||
Configuration file `piggybank.conf` is stored in directory specified by
|
Configuration file `piggybank.conf` is stored in directory specified by
|
||||||
`$XDG_CONFIG_HOME` environment variable or, if it isn't set, in `$HOME/.config`
|
`$XDG_CONFIG_HOME` environment variable or, if it isn't set, in `$HOME/.config`
|
||||||
on Linux and in `%APPDATA%` on Windows.
|
(which is exactly where `$XDG_CONFIG_HOME` points to) on Linux. On Windows it
|
||||||
|
is stored right in `%APPDATA%`.
|
||||||
|
|
||||||
By default it has following content:
|
Currently there are two options:
|
||||||
|
|
||||||
default-currency = SRUB
|
- `default-currency` sets default currency used for new piggy banks. Its default
|
||||||
|
value is `SRUB`.
|
||||||
|
- `currency.<ISO>` defines a currency. By default there are: RUB, SRUB (has no
|
||||||
|
coins of 1 and 5 kopek since they are extremely rare now), BYN, UAH, USD,
|
||||||
|
EUR and GBP.
|
||||||
|
|
||||||
Aside from `default-currency` there is also a `currency.*` parameter. `*` is a
|
Options are simple key=value storage. Spaces between `=` symbol are necessary.
|
||||||
currency's ISO code, e.g. `currency.RUB`, `currency.USD`, `currency.EUR` etc.
|
|
||||||
This parameter allows you to add a currency needed for you, but not presented in
|
|
||||||
program.
|
|
||||||
|
|
||||||
Currency is defined following way:
|
Currency is defined following way:
|
||||||
|
|
||||||
currency.ISO = ISO;NAME;DESCRIPTION;COINS_COUNT;COINS_NAME;FACE_VALUES
|
currency.<ISO> = <ISO>;<CURRENCY NAME>;<COINS COUNT>;{}<FRACTION SYMBOL>,
|
||||||
|
{}<CURRENCY SYMBOL>;<FACE VALUES>
|
||||||
|
|
||||||
That is best described with an example. Here it is:
|
That is best described with an example. Here it is:
|
||||||
|
|
||||||
currency.EXM = EXM;Example;Example currency;2;1E,2E;100,200
|
currency.EXM = EXM;Example;6;{}c,{}E;5,10,25,50,100,200
|
||||||
|
|
||||||
Yes, long and clunky way... May be I'll come up with something better.
|
|
||||||
|
@ -8,7 +8,7 @@ __all__ = ["__date__", "__version__", "__author__", "__email__",
|
|||||||
"VERSION"]
|
"VERSION"]
|
||||||
|
|
||||||
|
|
||||||
__date__ = "6 Jule 2020"
|
__date__ = "8 Jule 2020"
|
||||||
__version__ = "1.0.0"
|
__version__ = "1.0.0"
|
||||||
__author__ = "Alexander \"Arav\" Andreev"
|
__author__ = "Alexander \"Arav\" Andreev"
|
||||||
__email__ = "me@arav.top"
|
__email__ = "me@arav.top"
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
"""CLI: main"""
|
"""CLI"""
|
||||||
|
|
||||||
from re import search, split
|
from re import search, split
|
||||||
from sys import argv, stderr
|
from sys import argv, stderr
|
||||||
@ -24,7 +24,7 @@ Options:
|
|||||||
\t-L,--list-currencies -- list supported currencies and a default one;
|
\t-L,--list-currencies -- list supported currencies and a default one;
|
||||||
\t-r,--reversed -- change COINS' complementation from left to right.
|
\t-r,--reversed -- change COINS' complementation from left to right.
|
||||||
\t (e.g. 4 5 -> 0 0 0 0 4 5 by default; 4 5 0 0 0 0
|
\t (e.g. 4 5 -> 0 0 0 0 4 5 by default; 4 5 0 0 0 0
|
||||||
\t with this flag. If currency has 6 coins)
|
\t with this flag).
|
||||||
|
|
||||||
There are three actions available: put, take and show.
|
There are three actions available: put, take and show.
|
||||||
|
|
||||||
@ -115,8 +115,7 @@ def print_supported_currencies() -> None:
|
|||||||
"""Print a list of supported currencies."""
|
"""Print a list of supported currencies."""
|
||||||
print("Supported currencies are:")
|
print("Supported currencies are:")
|
||||||
for cur in CURRENCIES.keys():
|
for cur in CURRENCIES.keys():
|
||||||
print(f" {cur:^4} ┃ {CURRENCIES[cur].name:^31}"
|
print(f" {cur:^4} ┃ {CURRENCIES[cur].name:^31}")
|
||||||
f" ┃ {CURRENCIES[cur].description}")
|
|
||||||
print("Default currency is", Configuration()["default-currency"])
|
print("Default currency is", Configuration()["default-currency"])
|
||||||
|
|
||||||
def load_currencies() -> None:
|
def load_currencies() -> None:
|
||||||
@ -129,8 +128,8 @@ def load_currencies() -> None:
|
|||||||
def complement_list_of_coins(coins: List[int], currency: str,
|
def complement_list_of_coins(coins: List[int], currency: str,
|
||||||
_reversed: bool = False) -> List[int]:
|
_reversed: bool = False) -> List[int]:
|
||||||
"""Complements list of coins up to the count of currency's coins."""
|
"""Complements list of coins up to the count of currency's coins."""
|
||||||
offset_array = [0] * (len(CURRENCIES[currency]) - len(coins))
|
complementary = [0] * (len(CURRENCIES[currency]) - len(coins))
|
||||||
return offset_array + coins if not _reversed else coins + offset_array
|
return complementary + coins if not _reversed else coins + complementary
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
@ -13,7 +13,7 @@ Currency string has following format:
|
|||||||
{} with currency symbol used as a placeholder for where to put digits.
|
{} with currency symbol used as a placeholder for where to put digits.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
RUB;Russian ruble;8;{}коп.,{}₽;1,5,10,50,100,200,500,1000
|
RUB;Russian ruble;8;{} коп.,{}₽;1,5,10,50,100,200,500,1000
|
||||||
USD;US Dollar;6;{}¢,${};1,5,10,25,50,100
|
USD;US Dollar;6;{}¢,${};1,5,10,25,50,100
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@ -59,8 +59,7 @@ class Currency:
|
|||||||
coins_count -- number of face values of coins;
|
coins_count -- number of face values of coins;
|
||||||
fraction_symbol -- a symbol or word for a fraction of currency (e.g. c, cent);
|
fraction_symbol -- a symbol or word for a fraction of currency (e.g. c, cent);
|
||||||
currency_symbol -- a symbol or word for a currency (e.g. $);
|
currency_symbol -- a symbol or word for a currency (e.g. $);
|
||||||
face_values -- list of values for each face value in decimal
|
face_values -- list of values for each face value in decimal;
|
||||||
(e.g. $476.40 is 47640);
|
|
||||||
"""
|
"""
|
||||||
def __init__(self, iso_code: str, name: str, coins_count: int,
|
def __init__(self, iso_code: str, name: str, coins_count: int,
|
||||||
fraction_symbol: str, currency_symbol: str,
|
fraction_symbol: str, currency_symbol: str,
|
||||||
|
Loading…
Reference in New Issue
Block a user