get country and mcc relation
This commit is contained in:
parent
75947eec4b
commit
aee45136df
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,43 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
|
||||
# go to https://www.mcc-mnc.com/
|
||||
# copy whole table without headline to a txt file
|
||||
# run this to parse
|
||||
|
||||
|
||||
import pickle
|
||||
|
||||
with open("mcc_mnc_table.txt", "r") as f:
|
||||
lines = f.readlines()
|
||||
|
||||
country_to_code = {}
|
||||
code_to_country = {}
|
||||
for line in lines:
|
||||
tmp = list(filter(None, line.rstrip().split(' ')))
|
||||
country = tmp[2]
|
||||
mcc = int(tmp[0]) if not tmp[0] == 'n/a' else float('nan')
|
||||
mnc = int(tmp[1]) if not tmp[1] == 'n/a' else float('nan')
|
||||
provider = "unknown"
|
||||
for idx in range(3, len(tmp)):
|
||||
try:
|
||||
int(idx)
|
||||
break
|
||||
except BaseException:
|
||||
continue
|
||||
provider = " ".join(tmp[(idx+1):])
|
||||
|
||||
if country not in country_to_code:
|
||||
country_to_code[country] = []
|
||||
country_to_code[country].append((mcc, mnc, provider))
|
||||
|
||||
key = "{}_{}".format(mcc, mnc)
|
||||
if key not in code_to_country:
|
||||
code_to_country[key] = (country, provider)
|
||||
else:
|
||||
print("conflict??")
|
||||
print(key, country, provider)
|
||||
print(code_to_country[key])
|
||||
|
||||
pickle.dump(country_to_code, open("country_to_code.pickle", "wb"))
|
||||
pickle.dump(code_to_country, open("code_to_country.pickle", "wb"))
|
||||
Loading…
Reference in New Issue