import random
from string import lower
changdi_list=[]
def get_changdi():
path = "changdi.txt"
txt = open(path, "r")
#txt = open(path, "r", encoding="utf-8-sig")
for line in txt.readlines():
line = line.strip()
if len(line) >0:
changdi_list.append(str(line))
get_changdi()
#aa="756D"
place=[]
def getplace():
path = "history"
txt = open(path, "r")
#txt = open(path, "r", encoding="utf-8-sig")
for line in txt.readlines():
line = line.strip()
if len(line) >0:
place.append(str(line))
getplace()
lst= ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', \
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',\
'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
lst_int = map(lambda x: lst.index(x), lst)
keys = lst
values = list(lst_int)
d = dict(zip(keys, values))
def charToNum(c):
if c.isalpha():
return d[c]
#return ord(c)
else:
return c
def getID(aa):
restr="00"
for i in aa:
restr=restr+str(charToNum(lower(i)))
# print(restr)
while len(restr) <15:
restr = restr + '6'
# print(restr)
random.randint(0, 9)
while len(restr) <18:
restr = restr + str(random.randint(0,9))
# print(restr)
for i in place:
if restr == i:
print(i,"is been used")
return restr
#print(getID("023WE"))
for i in changdi_list:
#print(getID(i.split('-'[1])))
with open('result.txt',mode='a') as f, open('history',mode='a') as his_f:
changdi= i.strip()
tmplist= changdi.split('-')
#print(tmplist[0],len(tmplist))
if len(tmplist) >2:
deviceId = getID(tmplist[1].strip() )
print( deviceId )
f.write( deviceId +'\n')
his_f.write( deviceId +'\n')
elif tmplist[0]=="":
deviceId = ""
print( deviceId )
f.write( deviceId +'\n')
his_f.write( deviceId +'\n')
else:
deviceId = getID(tmplist[0].strip() )
print( deviceId )
f.write( deviceId +'\n')
his_f.write( deviceId +'\n')