def test(): phone_num = '13300001251' p = Phone() with open('province.txt', 'r') as f: province_list = f.read().splitlines() with open('province_ch.txt', 'r', encoding="utf-8") as f: province_ch_list = f.read().splitlines() try: desc = p.find(phone_num) # print(desc) # 返回归属的列表下标 index = province_ch_list.index(desc.get('province')) # print(desc.get('province'), index) if index is not None: # 如果下标存在,找到对应数据库的表名 use_table = province_list[index] insert_value(use_table, desc) else: with open('errorlog/descerror.txt', 'a', encoding='utf-8') as f: f.write(phone_num + '\n') # 无用手机号 except Exception as e: with open('errorlog/NoneType.txt', 'a', encoding='utf-8') as f: f.write(phone_num + '\n')
def Get_Excel_data(): file = './Tel.xlsx' #电话号码存储的excle表 re1 = xlrd.open_workbook(file) outwb = xlwt.Workbook() #创建工作簿 # print(type(outwb)) outws = outwb.add_sheet("new") #在工作簿中新建一个工作表new # print(type(outws)) # 读取第一个sheet ws = re1.sheet_by_index(0) rows = ws.nrows # print(rows) outws.write(0, 0, u'电话号') #给新表的第一行添加对应的标签 outws.write(0, 1, u'省份') outws.write(0, 2, u'城市') outws.write(0, 3, u'区号') outws.write(0, 4, u'运营商') for i in range(0, rows): Telvalue = int(ws.cell_value(i, 0)) # print(Telvalue) data = Phone().find(Telvalue) print(data) outws.write(i + 1, 0, Telvalue) #给新表的个列添加对应的数据 try: outws.write(i + 1, 1, data['province']) outws.write(i + 1, 2, data['city']) outws.write(i + 1, 3, data['area_code']) outws.write(i + 1, 4, data['phone_type']) outwb.save(r'New_Tel.xls') except: print("none")
def get_plid(): p = Phone() parameters = request.get_json().get("result").get("parameters") print request.get_json().get("result").get('contexts') try: brand = request.get_json().get("result").get('contexts')[3].get( "parameters").get("brand") except: brand = "Samsung" print "selected brand = {0}".format(brand) model_number = parameters.get('number', 0) if type(model_number) != int: model_number = int(parameters.get('number', 0).encode('ascii')) models = p.get_models_by_brand(brand) selected = models[model_number] print selected plid = p.get_plid(brand, selected) print plid result = {'speech': plid, 'displayText': plid} response = app.response_class(response=json.dumps(result), status=200, mimetype='application/json') return response
def data_to_csv(): from phone import Phone p = Phone() phone_place=[] phones =other_cell_phone for phone in phones: if(phone[0]=='1'): #手机号1开头,并且11位 if len(phone)==11: city = p.find(phone)['city'] phone_place.append(pinyin.get(city, format="strip", delimiter="")) #同时将地名转换为字符串 #phone_place.append(city) else: phone_place.append('Na') else: phone_place.append('Na') #不是手机号的话置Na festival_array=[] #节日列表 #print start_date1 for item in start_date1: if(item in festival.keys()): festival_array.append(festival[item]) else: festival_array.append('Na') #其他 #print len(other_cell_phone) #print len(start_weekday) #print len(start_hour) #print len(use_time) #print len(start_date1) #print len(place) #print len(phone_place) #print len(phone_calldays) #根据已有数组创建csv文件 columns=['phone_num','weekday','start_hour','use_time','start_date','location','other_phone_place','call_days'] dataframe=pd.DataFrame({'phone_num':other_cell_phone,'weekday':start_weekday,'start_hour':start_hour,'use_time':use_time,'start_date':start_date1,'location':place,'other_phone_place':phone_place,'call_days':phone_calldays}) dataframe.to_csv(address+'.csv',index=True,sep=',',columns=columns,encoding='utf-8') #默认写模式
def main(): phone_name = raw_input("Enter the name of your phone: ") number = int(raw_input("Enter your number: ")) phone = Phone(number, phone_name) print "Congratulations! You've set up your phone!" while True: display_menu() choice = raw_input("Please select an action: ") if choice == "0": display_menu() elif choice == "1": display_contacts(phone) elif choice == "2": first_name = raw_input("Enter the contact's first name: ") last_name = raw_input("Enter the contact's last name: ") number = int(raw_input("Enter the contact's number: ")) phone.add_contact(first_name, last_name, number) elif choice == "3": first_name = raw_input("Enter the contact's first name: ") last_name = raw_input("Enter the contact's last name: ") phone.del_contact(first_name) elif choice == "4": first_name = raw_input("Enter the contact's first name: ") last_name = raw_input("Enter the contact's last name: ") phone.call(first_name, last_name) elif choice == "5": first_name = raw_input("Enter the contact's first name: ") last_name = raw_input("Enter the contact's last name: ") message = raw_input("Enter the text message: ") phone.text(first_name, message) elif choice == "6": break else: print "Invalid selection. Please choose again."
def __init__(self, host, port, user, database, password): self.p = Phone() self.db = pymysql.connect(host=host, port=port, user=user, database=database, password=password) self.cursor = self.db.cursor()
def insert(self, id, brand, model, price, count, version): ''' 插入数据 :param phone: :return: ''' phone = Phone(id, brand, model, price, count, version) self.phones.append(phone)
def get_phone_region(phone_num): info = Phone().find(phone_num) if info is not None: region = info['province'] + ' ' + info['city'] + ' ' + info['phone_type'] else: region = '该号码暂未查询到归属地,请检查号码正确性或手动查询!' return region
def get_numbers_addr(self,number1,number2,number3): info1 = Phone().find(number1) info2 = Phone().find(number2) info3 = Phone().find(number3) try: phone1 = info1['phone'] province1 = info1['province'] city1 = info1['city'] zip_code1 = info1['zip_code'] area_code1 = info1['area_code'] phone_type1 = info1['phone_type'] except: print("Sorry,号码<%s>归属地信息系统暂时无法查询..." % number1) print("请登录http://www.ip138.com/sj/ 进行查询") else: print("手机号码:%s\n运营商:%s\n归属地:%s,%s\n邮编:%s\n区号:%s" % (phone1, phone_type1, province1, city1, zip_code1, area_code1)) print("*"*20) time.sleep(1) try: phone2 = info2['phone'] province2 = info2['province'] city2 = info2['city'] zip_code2 = info2['zip_code'] area_code2 = info2['area_code'] phone_type2 = info2['phone_type'] except: print("Sorry,号码<%s>归属地信息系统暂时无法查询..." % number2) print("请登录http://www.ip138.com/sj/ 进行查询") else: time.sleep(1) print("手机号码:%s\n运营商:%s\n归属地:%s,%s\n邮编:%s\n区号:%s" % (phone2, phone_type2, province2, city2, zip_code2, area_code2)) print("*" * 20) try: phone3 = info3['phone'] province3 = info3['province'] city3 = info3['city'] zip_code3 = info3['zip_code'] area_code3 = info3['area_code'] phone_type3 = info3['phone_type'] except: print("Sorry,号码<%s>归属地信息系统暂时无法查询..." % number3) print("请登录http://www.ip138.com/sj/ 进行查询") else: print("手机号码:%s\n运营商:%s\n归属地:%s,%s\n邮编:%s\n区号:%s" % (phone3, phone_type3, province3, city3, zip_code3, area_code3)) time.sleep(1)
def main(): smart_phone = Phone(2018, "Samsung", "$500", "32MB", "8", "555-666-7777") print("Yay", smart_phone.brand) print(str(smart_phone)) smart_phone.charge_battery(17) print("current battery", smart_phone.show_current_battery(), "hours") smart_phone.use_battery(4) print("current battery", smart_phone.show_current_battery(), "hours")
def init_hardware(): try: global phone phone = Phone() modem = Modem() phone.attach_modem(modem) except: deinit_hardware() raise
def getPhoneInfo(phoneNum): info = Phone().find(phoneNum) if info: phone = info['phone'] province = info['province'] city = info['city'] zip_code = info['zip_code'] area_code = info['area_code'] phone_type = info['phone_type'] return info
def add_phone(self): print(len(phone_id) + 1) brand = input('请输入手机品牌') model = input('请输入手机型号') price = float(input('请输入手机价格')) count = int(input('请输入手机数量')) version = input('请输入手机版本') phone_id.append(len(phone_id) + 1) p = Phone(brand, model, price, count, version) self.phone[len(phone_id)] = p print('添加成功')
def parseMobPhoneNum(phoneNum): mobileType, mobilePhone = guessPhoneType(phoneNum) if mobileType == 'mobile': phone_dict = Phone().find(mobilePhone) phoneProv = phone_dict['province'] phoneCity = phone_dict['city'] phoneType = phone_dict['phone_type'] phoneAreaCode = phone_dict['area_code'] phoneZipCode = phone_dict['zip_code'] return mobilePhone, phoneProv, phoneCity, phoneType, phoneAreaCode, phoneZipCode else: return '', '', '', '', '', ''
def get_info(phones): p = Phone() #phones = [18575670303,18588201231,15626585681] #print(phones) for phone in phones: try: city = p.find(phone)['city'] province = p.find(phone)['province'] print("%s %s %s" % (phone, province, city)) except: pass
def __init__(self, filename): """Initialises the instance with a given lable file. This method loads the given label file and populates the list of phones, which are parsed using the Phone class. :params filename: label file to be loaded """ self.phones = [] with open(filename, 'r') as f: for idx,l in enumerate(f.readlines()): self.phones.append(Phone(l,idx))
def run_once(self): """This method do the whole work""" # form socket list every time as list # could be moded in handlers socket_list = [self._asock, self._psock] for sock in self._users_list: socket_list.append(sock) infds, _, _ = select.select(socket_list, [], [], 1) for fds in infds: if fds is self._asock: sock, addr = fds.accept() self._loginfo('Admin connected from {}'.format(addr)) RemoteAdmin(self._users_list, sock, addr) socket_list.append(sock) continue if fds is self._psock: sock, addr = fds.accept() self._loginfo('Phone connected from {}'.format(addr)) Phone(self._order_number, self._users_list, sock, addr) self._order_number += 1 if self._order_number > 999: self._order_number = 0 socket_list.append(sock) continue if fds in self._users_list: user = self._users_list[fds] else: #unknows -> close self._logerror("uknown socket in list") socket_list.remove(fds) fds.close() continue data = fds.recv(1024) if not data: #closed self._loginfo('{} disconnected'.format(user.get_addr())) fds.close() socket_list.remove(fds) del self._users_list[fds] user.close() else: user.handle_data(data) # check timeouts for sock in list(self._users_list): user = self._users_list[sock] user.check_timeout()
def shaixuan(): # 打开csv print( '-----------------------------------------------------------------------------------------' ) print( '号码筛选小程序使用说明:\n(1)将号码保存到txt文件,每个号码一行;\n(2)将txt文件放到本程序当前目录下;\n(3)程序运行结束后将创建csv文件到当前目录下;\n' ) print('接下来请输入你要打开的txt文件名,如"xxx.txt",输入xxx即可') print( '-----------------------------------------------------------------------------------------' ) xxx = input('文件名是:') # 打开txt t1 = time.time() try: with open(xxx + '.txt', 'r', encoding='UTF-8') as f: tel_list = [] n = 0 nn = 0 for num in f: # print(num.strip()) # 把号码放入函数转换成字典 try: info = Phone().find(num.strip()) print(info) phone = info['phone'] province = info['province'] city = info['city'] zip_code = info['zip_code'] area_code = info['area_code'] phone_type = info['phone_type'] # 把字典里的值放入元组添加到列表 tel_list.append((phone, province, city, zip_code, area_code, phone_type)) n += 1 except Exception as e: print(e) print(num + '无法识别') nn += 1 except Exception as e: input('应该是文件名输错了,请检查后重试') else: # 遍历结束后,把列表写入到csv(一次性全部写入) ff = open(xxx + '.csv', 'a', newline='') writer = csv.writer(ff) writer.writerows(tel_list) f.close() ff.close() print('成功查找%s条数据,有%s条没找到' % (n, nn)) return t1
def get_models(): parameters = request.get_json().get("result").get("parameters") brand = parameters.get('brand') # print brand phone = Phone() models = phone.get_models_by_brand(brand) text = "Here are the available models for {0}:\n{1}".format(brand, models) result = {'speech': text, 'displayText': text} # print result response = app.response_class(response=json.dumps(result), status=200, mimetype='application/json') return response
def main(): smart_phone_1 = Phone(2018,"Samsung", "$500", "32MB","8","555-666-7777") smart_phone_2 = Phone(2018,"Apple", "$700", "32MB","8","444-555-666") # charge both phones smart_phone_1.charge_battery(8) smart_phone_2.charge_battery(8) # use some battery # use 4 hours on phone 1 and 2 hours on phone 2 smart_phone_1.use_battery(4) smart_phone_2.use_battery(2) # test the current battery of each are different print("battery life is the same:",smart_phone_1.current_battery == smart_phone_2.current_battery) # show the owner - they are the same print ("owner", smart_phone_1.owner) print ("owner", smart_phone_2.owner) # change the owner on Phone - at the class level not the object # level and see that it changes for both Phone.owner = "dylan" print ("owner", smart_phone_1.owner) print ("owner", smart_phone_2.owner)
def search(self, number): ph = Phone() city = ph.find(number) print(city) # 所有信息 print('手机号:' + number) print('所属省份:' + city['province']) print('所属市区:' + city['city']) print('邮 编:' + city['zip_code']) print('电话区号:' + city['area_code']) print('运 营 商:' + city['phone_type']) return city
def __init__(self): print 'Starting a new game' self.coordinates = (0, 0) self.location = GameLocation(self.x_offset, self.y_offset, self.width, self.height) self.vision = Vision(self.location) self.controller = Controller(self.x_offset, self.y_offset) self.phone = Phone() self._build_buttons() self._reset_food() self._build_customers() self._build_recipes() self.mat = GameObject('Mat', (199, 380))
def init_app(input, output): global i, o, phone i = input; o = output i.set_maskable_callback("KEY_ANSWER", answer) i.set_nonmaskable_callback("KEY_HANGUP", hangup) phone = Phone() try: #This not good enough - either make the systemctl library system-wide or add more checks os_call(["systemctl", "stop", "*****@*****.**"]) except Exception as e: print(repr(e)) #import pdb;pdb.set_trace() Thread(target=check_modem_connection, args=[True]).start()
class TraceMalware: def get_source_place(self, result_path): """ :param result_path: :return: """ try: with open(result_path, 'r') as fp: apk_info = json.load(fp) except Exception, e: print "can not open the file!" return p = Phone() for apk_name in apk_info: # apk中的移动电话归属地查询 if "mobilephone" in apk_info[apk_name]: print "apk_name", apk_name for phone_number in apk_info[apk_name]["mobilephone"]: # print phone_number p_source_info = p.find(phone_number) if type(p_source_info) is dict: print phone_number for p_info in p_source_info: print p_info, p_source_info[p_info] # apk 中的银行卡信息查询 if "bank_card" in apk_info[apk_name]: for bank_card in apk_info[apk_name]["bank_card"]: bank_info = self.get_bank_card_info(bank_card) if bank_info: print bank_card for key in bank_info: print key, bank_info[key] # apk中固定电话归属地查询 if "telephone" in apk_info[apk_name]: for tele_id in apk_info[apk_name]["telephone"]: if tele_id is None or len(tele_id)<10: continue tele_area = self.get_tele_num_place(tele_id[:4]) print tele_id, tele_area # apk中身份证号的归属地查询 if "id_card" in apk_info[apk_name]: for id in apk_info[apk_name]["id_card"]: id_result = self.get_id_card_place(id) print id, id_result
def addphone(self): nums = input('请输入手机编号:') for phone in self.db.phones: if nums == phone.id: print('编号已存在!请重新输出') return -1 brand = input('请输入手机品牌:') model = input('请输入手机型号:') price = input('请输入手机价格:') count = input('请输入手机数量:') version = input('请输入手机版本:') phone = Phone(nums,brand,model,price,count,version) self.db.insert(phone) self.db.commit()
def all_transformers(): return [ Email(), SMS(), FBMsg(), Phone(), BankWire(), Paypal(), DebitCard(), ContactlessCard(), Tube(), FBStatus(), Tweet(), ]
def get_number_addr(self,phoneNum): info = Phone().find(phoneNum) try: phone = info['phone'] province = info['province'] city = info['city'] zip_code = info['zip_code'] area_code = info['area_code'] phone_type = info['phone_type'] except: print("Sorry,号码<%s>归属地信息系统暂时无法查询..." % phoneNum) print("请登录http://www.ip138.com/sj/ 进行查询") else: print("手机号码:%s\n运营商:%s\n归属地:%s,%s\n邮编:%s\n区号:%s" % (phone, phone_type, province, city, zip_code, area_code))
def main(): import config phone = Phone() phone.setSoundDevices(config.SND_SPK, config.SND_MIC, config.SND_RING) phone.register(config) gui = Gui() controller = Controller(phone, gui) import time while True: phone.loop() gui.loop() time.sleep(0.1)
def get_brands(): """ gets list of phones from root API :return: list of supported phone models """ phone = Phone() brands = phone.get_brands() text = "Sure! Here are the available brands:\n " \ "{0}\n" \ "What do you want?".format(brands) result = {'speech': text, 'displayText': text} # print result response = app.response_class(response=json.dumps(result), status=200, mimetype='application/json') return response
def extract_cellphone_location(self, phoneNum, nation='CHN'): """ extract cellphone number locations according to the given number eg: extract_cellphone_location('181000765143',nation=CHN) :param: phoneNum<string>, nation<string> :return: location<dict>{'phone': '18100065143', 'province': '上海', 'city': '上海', 'zip_code': '200000', 'area_code': '021', 'phone_type': '电信'} """ if nation=='CHN': p = Phone() loc_dict = p.find(phoneNum) if nation!='CHN': x = phonenumbers.parse(phoneNum, 'GB') if phonenumbers.is_possible_number(x): loc_dict = x # print(loc_dict) return loc_dict