1
0
Fork 0

Yet another refactoring finished. Version is still 1.0.0 because it was never released before.

This commit is contained in:
Alexander Andreev 2020-07-08 02:10:35 +04:00
parent 33ec32cb18
commit bab9fda3fb
4 changed files with 27 additions and 32 deletions

View File

@ -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
you decide to take them all out.
Yes, only coins, no banknots. Well, you actually can easily add support for
banknots, but table will become indeed wide.
Yes, only coins, no banknots. Well, you actually can easily add them, but table
will become indeed wide.
# Usage
@ -15,13 +15,9 @@ banknots, but table will become indeed wide.
Common options:
- `-h,--help` — print this help;
- `-v,--version` — print program version;
- `-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
### 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
significant face value to the most significant one and as stated above being
complemented from left so a set shorter than number of coins in a currency,
e.g. 5 8 4 will be interpreted as 0 0 0 5 8 4. And this flag will make it
to be interpreted as 5 8 4 0 0 0. It is convenient if you want to add only
coins of low face value (e.g. cents).
significant face value to the most significant one and being complemented from
left so a set shorter than number of coins in a currency, e.g. 5 8 4 will be
interpreted as 0 0 0 5 8 4. And this flag will make it to be interpreted
as 5 8 4 0 0 0. It is convenient if you want to add only coins of low face
value (e.g. cents).
`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.
@ -118,23 +114,24 @@ piggybank show example.pb with t
Configuration file `piggybank.conf` is stored in directory specified by
`$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
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.
Options are simple key=value storage. Spaces between `=` symbol are necessary.
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:
currency.EXM = EXM;Example;Example currency;2;1E,2E;100,200
Yes, long and clunky way... May be I'll come up with something better.
currency.EXM = EXM;Example;6;{}c,{}E;5,10,25,50,100,200

View File

@ -8,7 +8,7 @@ __all__ = ["__date__", "__version__", "__author__", "__email__",
"VERSION"]
__date__ = "6 Jule 2020"
__date__ = "8 Jule 2020"
__version__ = "1.0.0"
__author__ = "Alexander \"Arav\" Andreev"
__email__ = "me@arav.top"

View File

@ -1,4 +1,4 @@
"""CLI: main"""
"""CLI"""
from re import search, split
from sys import argv, stderr
@ -24,7 +24,7 @@ Options:
\t-L,--list-currencies -- list supported currencies and a default one;
\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 with this flag. If currency has 6 coins)
\t with this flag).
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("Supported currencies are:")
for cur in CURRENCIES.keys():
print(f" {cur:^4}{CURRENCIES[cur].name:^31}"
f"{CURRENCIES[cur].description}")
print(f" {cur:^4}{CURRENCIES[cur].name:^31}")
print("Default currency is", Configuration()["default-currency"])
def load_currencies() -> None:
@ -129,8 +128,8 @@ def load_currencies() -> None:
def complement_list_of_coins(coins: List[int], currency: str,
_reversed: bool = False) -> List[int]:
"""Complements list of coins up to the count of currency's coins."""
offset_array = [0] * (len(CURRENCIES[currency]) - len(coins))
return offset_array + coins if not _reversed else coins + offset_array
complementary = [0] * (len(CURRENCIES[currency]) - len(coins))
return complementary + coins if not _reversed else coins + complementary
def main():

View File

@ -13,7 +13,7 @@ Currency string has following format:
{} with currency symbol used as a placeholder for where to put digits.
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
"""
@ -59,8 +59,7 @@ class Currency:
coins_count -- number of face values of coins;
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. $);
face_values -- list of values for each face value in decimal
(e.g. $476.40 is 47640);
face_values -- list of values for each face value in decimal;
"""
def __init__(self, iso_code: str, name: str, coins_count: int,
fraction_symbol: str, currency_symbol: str,