-
#!/usr/bin/env python
-
#_*_ coding:utf-8 _*_
-
import os,sys
-
if os.path.isfile('menu_info.txt'):
-
pass
-
else:
-
sys.exit("\033[31m没有定义menu_info.txt\033[0m")
-
-
usr_dic = {}
-
with open('menu_info.txt') as f1:
-
for i in f1:
-
area_dic = {}
-
l1 = i.split(':')
-
# usr_dic[l1[0]] = l1[1]
-
l2 = l1[1].strip('\n').split(' ')
-
d1 = {}
-
for i in l2:
-
l3 = i.split('|')
-
# d1[l3[0]] = l3[1]
-
# print (d1)
-
l4 = l3[1].split(';')
-
d2 = {}
-
for m in l4:
-
l5 = m.split('*')
-
d2[l5[0]] = l5[1]
-
d1[l3[0]] = d2
-
# print (d1)
-
usr_dic[l1[0]] = d1
-
#print (usr_dic)
-
while True:
-
li_m = []
-
for m,n in enumerate(usr_dic,1):
-
print (m,n) #打印出城市和序列号
-
li_m.append(m)
-
city_code = input("\033[32mplease input your right code or 'q'(quit):\033[0m")
-
if city_code in str(li_m):
-
for m, n in enumerate(usr_dic, 1):
-
if m == int(city_code):
-
-
while True:
-
li_x = []
-
for x,y in enumerate(usr_dic[n],1):
-
print (x,y) #打印出区信息
-
li_x.append(x)
-
res_code = input("\033[32mplease input: your 'area_code' or 'b' or 'q'(b:back q:quit):\033[0m")
-
if res_code in str(li_x):
-
for x,y in enumerate(usr_dic[n],1):
-
# print (x,y,usr_dic[n][y])
-
if res_code == str(x):
-
-
while True:
-
li_u = []
-
for u,v in enumerate(usr_dic[n][y],1):
-
print (u,v) #打印出镇的信息
-
li_u.append(u)
-
town_code = input("\033[32mplease input: your 'area_code' or 'b' or 'q'(b:back q:quit):\033[0m")
-
if town_code in str(li_u):
-
# print (town_code)
-
for u, v in enumerate(usr_dic[n][y],1):
-
if u == int(town_code):
-
# print (u,usr_dic[n][y][v])
-
print (usr_dic[n][y][v]) #打印镇的具体地点信息
-
sys.exit(0)
-
elif town_code == 'b':
-
break
-
elif town_code == 'q':
-
sys.exit('\033[32mByeBye\033[0m')
-
else:
-
print ('\033[31merror input,please input agin\033[0m')
-
elif res_code == 'b':
-
break
-
elif res_code == 'q':
-
sys.exit('\033[32mByeBye\033[0m')
-
else:
-
print ('\033[31merror input,please input again\033[0m')
-
elif city_code == 'q':
-
sys.exit('\033[32mByeBye\033[0m')
-
else:
-
print ("\033[31merror input,please input again\033[0m")
[yn@localhost@../menu]$cat menu_info.txt
北京:朝阳|三里屯*三里屯医院,三里屯小学;潘家园*潘家园街道办事处,潘家园小学 昌平|沙河*老男孩教育,沙河链家地产;回龙观*回龙观中学,回龙观公园
上海:徐家汇|徐家汇街道*徐家汇福特4s店,徐家汇中学;长桥街道*长桥小学,长桥医院 闵行区|七宝镇*七宝镇中学,如家七宝镇店;马桥镇*马桥医院,马桥小学
深圳:福田|福田街办*福田小学,福田幼儿园;梅林街办*梅林医院,梅林中学 南山区|蛇口*家家顺蛇口店,蛇口办事处;南头*南山小学,南山集团