def find(cardSeg):
	userDefine = 90
	current = cardSeg * 10000 + userDefine
	p = Phone()
	fp = open('result.txt', 'a')

	while (current <= (cardSeg * 10000+9990)):
		print current
		
		if (p.find(current) != None):
			'''
			print p.find(current)
			print p.find(current)['province'].decode('utf-8')
			print p.find(current)['city'].decode('utf-8')
			print p.find(current)['phone_type'].decode('utf-8')
			'''
			fp.write(str(current)+' \t')
			fp.write(p.find(current)['province']+' \t')
			fp.write(p.find(current)['city']+' \t')
			fp.write(p.find(current)['phone_type']+'\n')
			
		current += 100
	
	fp.close()
	print 'finished'
Esempio n. 2
0
File: Q.PY Progetto: wansoft/WANPLAN
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
Esempio n. 3
0
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')
Esempio n. 4
0
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') #默认写模式
Esempio n. 5
0
    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
Esempio n. 6
0
class TestPhone(TestCase):

    def setUp(self):
        self.p = Phone()

    def tearDown(self):
        pass

    def test_get_phone_no_type(self):

        self.assertEqual(self.p.get_phone_no_type(1), '移动')
        self.assertEqual(self.p.get_phone_no_type(2), '联通')
        self.assertEqual(self.p.get_phone_no_type(3), '电信')
        self.assertEqual(self.p.get_phone_no_type(6), '移动虚拟运营商')
        self.assertEqual(self.p.get_phone_no_type(5), '联通虚拟运营商')
        self.assertEqual(self.p.get_phone_no_type(4), '电信虚拟运营商')
        self.assertEqual(self.p.get_phone_no_type(7), None)

    def test_find_on_assert_error(self):

        try:
            self.p.find(123)
            self.assertTrue(False)
        except AssertionError:
            pass

    def test_find_on_ok(self):

        res = self.p.find(1521147)
        self.assertEqual(res['zip_code'], '421000')
        self.assertEqual(res['area_code'], '0734')
        self.assertEqual(res['city'], '衡阳')
        self.assertEqual(res['province'], '湖南')
        self.assertEqual(res['phone_type'], '移动')

    def test_find_on_no_res(self):

        res = self.p.find(1991147)
        self.assertEqual(res, None)
Esempio n. 7
0
class TestPhone(TestCase):
    def setUp(self):
        self.p = Phone()

    def tearDown(self):
        pass

    def test_get_phone_no_type(self):

        self.assertEqual(self.p.get_phone_no_type(1), '移动')
        self.assertEqual(self.p.get_phone_no_type(2), '联通')
        self.assertEqual(self.p.get_phone_no_type(3), '电信')
        self.assertEqual(self.p.get_phone_no_type(6), '移动虚拟运营商')
        self.assertEqual(self.p.get_phone_no_type(5), '联通虚拟运营商')
        self.assertEqual(self.p.get_phone_no_type(4), '电信虚拟运营商')
        self.assertEqual(self.p.get_phone_no_type(7), None)

    def test_find_on_assert_error(self):

        try:
            self.p.find(123)
            self.assertTrue(False)
        except AssertionError:
            pass

    def test_find_on_ok(self):

        res = self.p.find(1521147)
        self.assertEqual(res['zip_code'], '421000')
        self.assertEqual(res['area_code'], '0734')
        self.assertEqual(res['city'], '衡阳')
        self.assertEqual(res['province'], '湖南')
        self.assertEqual(res['phone_type'], '移动')

    def test_find_on_no_res(self):

        res = self.p.find(1991147)
        self.assertEqual(res, None)
Esempio n. 8
0
def phone_city(calls):
    try:
        call = Phone()
        a = []
        for i in calls:
            try:
                call1 = call.find(i.strip())
                pro = call1['province']
                ci = call1['city']
                info = i + '\t' + pro + '\t' + ci
                # print(info)
                a.append(info)
            except Exception as e:
                # print(e)
                pass
        return a
    except Exception as e:
        print(e)
        pass
Esempio n. 9
0
    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
Esempio n. 10
0
class App(object):
    def __init__(self):
        self.gi = Phone('phone.dat')
        self.gi2 = pygeoip.GeoIP('GeoLiteCity.dat')
        self.root = tkinter.Tk()
        self.menubar = Menu(self.root)
        filemenu = Menu(self.menubar, tearoff=0)
        self.menubar.add_cascade(label='图片编辑', menu=filemenu)
        self.root['menu'] = self.menubar
        filemenu.add_command(
            label="压缩图片",
            command=lambda: self.compressImage('pic', 'mini_pic'))
        filemenu.add_command(label="帮助", command=self.help)
        filemenu.add_command(label="关于", command=self.about)
        filemenu.add_command(label="退出", command=self.root.quit)
        self.root.title("ip地址和号码归属地查询、批量压缩图片小工具")
        self.Label = tkinter.Label(self.root, text="请输入IP地址或者电话号码:", width=50)
        self.text_input = tkinter.Entry(self.root, width=30)
        self.display_info = tkinter.Listbox(self.root, width=50)
        self.result_button = tkinter.Button(self.root,
                                            background='blue',
                                            command=self.find_position,
                                            text="查询")

    def about(self):
        messagebox.showinfo(
            '关于',
            '作者:darwin \n verion 1.0 \n 感谢您的使用! \n [email protected] ')

    def help(self):
        messagebox.showinfo(
            '帮助',
            '在当前目录下建名为‘pic’文件夹,\n将需要压缩的图片放入点击压缩,\n压缩后的图片会在当前目录下,\n一个名为‘pic_mini’的文件夹中。'
        )

    def compressImage(self, srcPath, dstPath):
        for filename in os.listdir(srcPath):
            if not os.path.exists(dstPath):
                os.makedirs(dstPath)
            srcFile = os.path.join(srcPath, filename)
            dstFile = os.path.join(dstPath, filename)
            if os.path.isfile(srcFile):
                sImg = Image.open(srcFile)
                w, h = sImg.size
                dImg = sImg.resize((w // 3, h // 3), Image.ANTIALIAS)
                dImg.save(dstFile)
            if os.path.isdir(srcFile):
                compressImage(self, srcFile, dstFile)

    def gui_arrang(self):
        self.Label.pack()
        self.text_input.pack()
        self.display_info.pack()
        self.result_button.pack()

    def find_position(self):
        self.text_addr = self.text_input.get()
        if re.match(r"^1[35678]\d{9}$", self.text_addr):
            aim = self.gi.find(self.text_addr)
            try:
                phones = aim["phone"]
                phone_type = aim["phone_type"]
                province = aim["province"]
                city = aim["city"]
                zip_code = aim["zip_code"]
                area_code = aim["area_code"]
            except:
                pass
            the_info = [
                "号段:" + str(phones), "公司:" + str(phone_type),
                "省份:" + str(province), "城市:" + str(city),
                "邮编:" + str(zip_code), "座机:" + str(area_code),
                "需要查询的号段:" + str(self.text_addr)
            ]
            for item in range(10):
                self.display_info.insert(0, "")
            for item in the_info:
                self.display_info.insert(0, item)
            return the_info
        elif re.match(r"^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$", self.text_addr):
            aim = self.gi2.record_by_addr(self.text_addr)
            try:
                city = aim["city"]
                region_code = aim["region_code"]
                country_name = aim["country_name"]
                longitude = aim["longitude"]
                latitude = aim["latitude"]
            except:
                pass
            the_info = [
                "城市:" + str(city), "编号:" + str(region_code),
                "国家:" + str(country_name), "纬度:" + str(longitude),
                "经度:" + str(latitude), "需要查询的IP:" + str(self.text_addr)
            ]
            for item in range(10):
                self.display_info.insert(0, "")
            for item in the_info:
                self.display_info.insert(0, item)
            return the_info
        else:

            the_info = "请输入正确的ip、手机号码地址!"
            self.display_info.insert(0, the_info)
            return the_info
Esempio n. 11
0
File: hh.py Progetto: wyf8468/nemmp
# coding:utf8
import xlrd
from phone import Phone

p = Phone()
c = '15854648273'  # 手机号
city = p.find(c)
print(city)  # 所有信息
print('手机号:' + c)
print('所属省份:' + city['province'])
print('所属市区:' + city['city'])
print('邮    编:' + city['zip_code'])
print('电话区号:' + city['area_code'])
print('运 营 商:' + city['phone_type'])
Esempio n. 12
0
import numpy as np

from phone import Phone

# f = open("/Users/duncan/pycharmprojects/My-Tools-Code/Python/phone/phone.dat")
# c = np.fromfile("/Users/duncan/pycharmprojects/My-Tools-Code/Python/phone/phone.dat", dtype=int)
# print(c)

p = Phone()
print(p.find("13311050833"))
Esempio n. 13
0
exceps = []
for i in source_xls:
    print()
    print(i)
    try:
        wb = xlrd.open_workbook(i)
        for sheet in wb.sheets():
            for rownum in range(sheet.nrows):
                tmp_datas = sheet.row_values(rownum)
                tmp_datas_true = []
                for tmp_data in tmp_datas:
                    cell_nums = re.findall(r'1\d{10}', str(tmp_data))
                    if cell_nums:
                        for cell_num in cell_nums:
                            if p.find(cell_num)['province'] == '上海':
                                tmp_datas_true.append(cell_num)
                if tmp_datas_true:
                    for tmp_data_true in tmp_datas_true:
                        data.append(tmp_data_true)
                        print(tmp_data_true)
    except Exception as e:
        exceps.append(e)
        failed_file_paths.append(i)

print()

# 写入数据
workbook = xlsxwriter.Workbook(target_xls)
worksheet = workbook.add_worksheet()
worksheet.set_column('A:A', 20)
Esempio n. 14
0
class PhoneData:
    """按照运营商批量生成手机号,并根据归属地存储到数据库"""
    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 __def__(self):
        self.db.close()

    def create_phone(self, prefix_list, province_list, province_ch_list):
        """ 判断手机号归属地,并插入到对应表中 """

        for prefix in prefix_list:
            i = 0
            count = 1
            while i < 100000000:
                # 生成手机号
                phone_num = str(int(prefix) * 100000000 + i)
                i += 1
                # 查找每个手机号的归属地信息
                try:
                    desc = self.p.find(phone_num)
                    # 返回归属的列表下标
                    index = province_ch_list.index(desc.get('province'))
                    # print(desc.get('province'), index)
                    if index is not None:
                        # 如果下标存在,找到对应数据库的表名
                        use_table = province_list[index]
                        # 调入函数,插入到数据库中
                        self.insertdb(use_table, desc, count)
                        count += 1
                    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 insertdb(self, use_table, desc, count):
        """向数据库中插入手机号码"""
        value_list = []

        sql = "INSERT INTO %s (phone, pro, city, mark, checked, company) values ('%s', '%s', '%s', 0, 0, '%s')" % \
              (use_table, desc.get('phone'), desc.get('province'), desc.get('city'), desc.get('phone_type'))
        try:
            print('第%s个' % count + sql)
            self.cursor.execute(sql)
            if count % 1000 == 0:
                self.db.commit()
        # 写入数据库错误
        except Exception as e:
            with open('errorlog/sqlerrorlog.txt', 'a', encoding='utf8') as f:
                f.write(str(e) + '\n')
            self.db.rollback()
Esempio n. 15
0
from phone import Phone
import sys
p  = Phone()
while True:
    phone_num = input('please enter your phone number: ')
    if phone_num == 'exit':
        sys.exit(1)
    print(p.find(phone_num))
Esempio n. 16
0
    #sheet = excel.get_sheet_by_name(sheet_name)  # 读取指定名页签
    sheet = 1
    phone_col = sheet['I']  # 拿到C列
    for index in range(2, len(phone_col) + 1):  # 从C列第2行开始循环
        phone_data = sheet['I%s' % index]  # 拿到C列当前行单元格对象
        phone_num = phone_data.value.strip()  # 去除号码前后空格,得到号码字符串
        phone_region = get_phone_region(phone_num)  # 获得当前号码归属地
        print(phone_region)
        print('正在向J列第' + str(index) + '行(对应号码为' + phone_num + ')写入归属地信息: ' + phone_region)  # 打印出行数,号码,地区信息
        sheet['J%s' % index] = phone_region  # 将归属地内容写入D列对应行
    excel.save(excel_path)
if __name__ == '__main__':
    try:
        excel_path = "wuhan.xlsx"
        print("已读取excel")
        #sheet_name = input('请输入你要操作的sheet名(如果仅有一个sheet,请直接按enter):')
        #if sheet_name.strip() == '':
         #   sheet_name = None
        print("已进入")
        add_exl(excel_path)

    except Exception as e:
        print('[ERROR]发生错误:%s' % e)
p = Phone()
y=p.find(15629668188)
lct = y['province']+ ' ' + y['city'] + ' ' + y['phone_type']
pnumber = y['area_code']+' ' +y['phone']
print(pnumber)
print(lct)
print(y)
#return {'phone': '18100065143', 'province': '上海', 'city': '上海', 'zip_code': '200000', 'area_code': '021', 'phone_type': '电信'}
Esempio n. 17
0
def test():
	p  = Phone()
	print p.find(1888888)
	print p.find(1888888)['province'].decode('utf-8')
	print p.find(1888888)['city'].decode('utf-8')
	print p.find(1888888)['phone_type'].decode('utf-8')
Esempio n. 18
0
count = 0
n = 0
i = 1
data = xlrd.open_workbook(pathIn)
tables = data.sheets()[0]
arr_two = []
while i < num:
    phone = int(tables.cell_value(i, 0))  # 获取电话
    call_duration = tables.cell_value(i, 2)  # 获取对应通话时间
    call_duration = "%.3f" % call_duration

    # print(call_duration)
    phones.append(phone)
    # print(phones)
    if len(str(phone)) == 11:
        province = p.find(phone)['province']
        city = p.find(phone)['city']
        location = province + city
        arr[location] = count
        if location in arr.keys():
            count = float(call_duration) + float(count)
            arr[location] = count
            print(arr)
    else:
        arr_two.append(phone)
        print(arr_two)




    """