-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcurrency_codes.py
47 lines (31 loc) · 1.15 KB
/
currency_codes.py
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
"""
Generates currencies based on https://en.wikipedia.org/wiki/ISO_4217
Data gathered from https://github.com/datasets/currency-codes/blob/master/data/codes-all.csv
"""
import os
import urllib.request
import csv
data_url = 'https://raw.githubusercontent.com/datasets/currency-codes/master/data/codes-all.csv'
response = urllib.request.urlopen(data_url)
data = response.read()
text = data.decode('utf-8')
reader = csv.reader(text.splitlines())
with open(os.path.join("moneypy", "currencies.py"), "w") as f:
f.write("""\"\"\"
List of currencies from ISO 4217
\"\"\"
from .currency import Currency
""")
added = []
for row in reader:
entity, currency, alphacode, numcode, minorunit, withdrawaldate = row
if alphacode == 'AlphabeticCode':
continue
if alphacode != '':
if numcode == '':
numcode = 'None'
if minorunit == '' or minorunit == '-':
minorunit = 0
if alphacode not in added:
f.write(f"{alphacode}_CURRENCY = Currency('{currency}', '{alphacode}', '{numcode}', {minorunit})\n")
added.append(alphacode)