diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2023-08-11 14:07:32 +0200 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2023-08-11 14:07:32 +0200 |
| commit | b17559d8ede422a0b91bcc1a2a01e71cd9b905b3 (patch) | |
| tree | 426ef44932c343fae9a426ca6267342826b80ffc /utils.py | |
| parent | a16f0be99ea25e9102c9863db6c32dd4cb96c0a7 (diff) | |
| download | geldschieberbot-b17559d8ede422a0b91bcc1a2a01e71cd9b905b3.tar.gz geldschieberbot-b17559d8ede422a0b91bcc1a2a01e71cd9b905b3.zip | |
extract the models and utility function into separate source files
Diffstat (limited to 'utils.py')
| -rw-r--r-- | utils.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/utils.py b/utils.py new file mode 100644 index 0000000..353e562 --- /dev/null +++ b/utils.py @@ -0,0 +1,28 @@ +"""Utility functions used by the geldschieberbot""" + + +def to_cent(euro) -> int: + """Parse string containing euros into a cent value""" + if '.' in euro: + euro = euro.split('.') + else: + euro = euro.split(',') + if len(euro) > 2: + raise TypeError + euro[0] = int(euro[0]) + if len(euro) < 2: + euro.append(0) + else: + if len(euro[1]) == 1: + euro[1] = int(euro[1]) * 10 + else: + euro[1] = int(euro[1]) + amount = euro[0] * 100 + euro[1] + if amount < 0: + raise ValueError + return amount + + +def to_euro(cents) -> str: + """Format cents as euro""" + return f"{cents/100:.2f}" |
