-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgen_currencies.py
More file actions
54 lines (44 loc) · 1.26 KB
/
gen_currencies.py
File metadata and controls
54 lines (44 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from xml.etree.ElementTree import Element, parse
currencies = set[str]()
ISO_4217 = parse('./list-one.xml').getroot()
match ISO_4217:
case Element(tag = 'ISO_4217'):
for CcyTbl in ISO_4217:
match CcyTbl:
case Element(tag = 'CcyTbl'):
for CcyNtry in CcyTbl:
match CcyNtry:
case Element(tag = 'CcyNtry'):
ccys = list(CcyNtry.iter('Ccy'))
if len(ccys) == 0:
continue
ccy, = ccys
assert ccy.text
currencies.add(ccy.text)
case _:
pass
case _:
pass
case _:
assert False
currencies = sorted(currencies)
for currency in currencies:
assert '\'' not in currency
with open('src/mundane/_currencies.py', 'w') as out:
out.write(f'''from ._typed_money import TypedMoney
__all__ = [{', '.join(f'\'{currency}\'' for currency in currencies)}]
''')
for currency in currencies:
out.write(f'''
class {currency}(TypedMoney):
pass
''')
with open('src/mundane/__init__.py', 'w') as out:
out.write(f'''# isort: skip_file
from ._currency import Currency
from ._money import Money
from ._any_money import AnyMoney
from ._typed_money import TypedMoney
from ._currencies import *
__all__ = ['Currency', 'Money', 'AnyMoney', 'TypedMoney', {', '.join(f'\'{currency}\'' for currency in currencies)}]
''')