get country and mcc relation

This commit is contained in:
HappyZ 2019-06-09 14:39:26 -05:00
parent 75947eec4b
commit aee45136df
4 changed files with 1733 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@ -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"))