예제 #1
0
파일: Cpassword.py 프로젝트: 0ps/Cpassword
class Cpassword():
    
    def __init__(self, pinyinusername):
        self.pinyinusername = pinyinusername
        self.yinwen = None
        self.pinyin = PinYin()
        self.pinyin.load_word()
        self.num = 0
        self.strname = ''
        self.struser = ''
        self.listDict = []
        self.threadlist = []
    def run(self):
        self.returnUser = self.readYz()
        if self.returnUser is not False:
            for self.userxing in self.pinyin.hanzi2pinyin(self.returnUser):
                self.strname = self.strname + self.userxing[0]
            self.threadlist.append(self.strname)
            for self.userming in self.pinyin.hanzi2pinyin(self.returnUser)[1:]:
                self.struser = self.struser + self.userming[0]
            self.usernamefirst = self.pinyin.hanzi2pinyin(self.returnUser)[0]
            self.struser = self.usernamefirst + self.struser
            self.threadlist.append(self.struser)
            #print self.threadlist
            self.createDict(self.threadlist)

    def createDict(self, userstr):
        self.userstr = userstr
        self.strlist = [self.userstr[0], self.userstr[0].upper(), self.userstr[0].capitalize(),self.userstr[1],\
            self.userstr[1].upper(),self.userstr[1].capitalize()]
        self.writeFile = open('output/userdict.txt', 'a')
        with open('lib/dict.txt') as self.openDict:
            for self.line in self.openDict:
                self.listDict.append(self.line)
        for self.userDict in self.strlist:
            for self.i in self.listDict:
                self.writeFile.write(self.userDict + self.i.strip() + '\n')
        self.writeFile.close()

    def readYz(self):
        with open('lib/payload.txt') as self.cpassDict:
            for self.line in self.cpassDict.readlines():
                if self.pinyinusername == self.line.split('-')[0]:
                    self.num = self.num + 1
                    return self.line.split('-')[1].strip()
        if self.num == 0:
            print self.pinyinusername + '   not found in lib/payload.txt'
            logging.info(self.pinyinusername + '  not found chinese name please enter lib/payload.txt' + '\n')
            return False
예제 #2
0
def init():
    global file, en, test, DB, cursor, ip_queue
    en = int(sys.argv[2])
    if en > 0:  # 英文需要传0,中文需要传1
        test = PinYin()
        test.load_word()
    # 打开数据库连接
    DB = MySQLdb.connect("47.99.121.124",
                         "root",
                         "123456",
                         "test",
                         charset='utf8')
    # 使用cursor()方法获取操作游标
    cursor = DB.cursor()
    DB.autocommit(True)
 def pinyin_item(self):
     # pinyin dict
     self.py = PinYin('pinyin/word.data')
     self.py.load_word()
     for i, item in enumerate(self.lis):
         # 拼音化
         han_item = ''
         all_pin = first_pin = ''
         for x in item[0].split(' '):
             han_item += x
         item_pinyin = self.py.hanzi2pinyin_split(string=han_item, split=" ")
         for x in item_pinyin.split(' '):
             if x != '':
                 all_pin += x
                 first_pin += x[0]
         res_pin = item_pinyin + ' ' + all_pin + ' ' + first_pin
         self.lis[i][3] = res_pin
예제 #4
0
파일: Cpassword.py 프로젝트: 0ps/Cpassword
 def __init__(self, pinyinusername):
     self.pinyinusername = pinyinusername
     self.yinwen = None
     self.pinyin = PinYin()
     self.pinyin.load_word()
     self.num = 0
     self.strname = ''
     self.struser = ''
     self.listDict = []
     self.threadlist = []
예제 #5
0
import json
from collections import OrderedDict

import copy
import requests
import pymongo
import time
from requests.exceptions import RequestException
from datetime import date
from pinyin.pinyin import PinYin

from config import *

py = PinYin()
py.load_word()


class Evcard(object):
    def __init__(self):
        self._data = self.setData()
        #     {
        #         'AreaCodeList': [None, self.saveAreaCodeList,self.saveAreaCodeListToMongo,self.uploadAreaCodeList],
        #         'ShopInfoList': [None, self.saveCityShopInfoList,self.saveCityShopInfoListToMongo,self.uploadCityShopInfoList],
        #         'VehicleModeList': [None, self.saveVehicleModeList,self.saveVehicleModeListToMongo,self.uploadVehicleModeList]
        #     }
        # )
        self.cityDict = None
        self.cityList = None
        self.cityListEN = None
        self._client = self.setClient()
class bookmark_searcher(object):
    # in windows
    bookmark_name = os.path.join(os.path.expanduser("~"), 'AppData//Local//Google//Chrome//User Data//Default',
                                 'Bookmarks')
    # in mac
    #bookmark_name = os.path.join(os.path.expanduser("~"), 'Library/Application Support/Google/Chrome/Default',
            #                     'Bookmarks')

    def __init__(self, in_name=bookmark_name):
        self.lis = []
        data = self.load(in_name)
        child_items = data['roots']['bookmark_bar']['children']
        self.make_list(child_items)  # 将数据准备好
        self.pinyin_item()  # 将pinyin准备好


    def store(self, data, store_name='data.json'):
        with open(store_name, 'w') as json_file:
            json_file.write(json.dumps(data))

    def load(self, load_name):
        with open(load_name, encoding='UTF-8') as json_file:
            data = json.load(json_file)
            return data

    def make_list(self, child_items):
        for item in child_items:
            if 'children' in item.keys():
                # print(item['name']) # 类别标签
                # print(type(item['children']))
                self.make_list(item['children'])
            else:
                mItem = [item['name'], item['url'], item['date_added'], '']
                self.lis.append(mItem)
                # print(item['name'],item['url'])

    def pinyin_item(self):
        # pinyin dict
        self.py = PinYin('pinyin/word.data')
        self.py.load_word()
        for i, item in enumerate(self.lis):
            # 拼音化
            han_item = ''
            all_pin = first_pin = ''
            for x in item[0].split(' '):
                han_item += x
            item_pinyin = self.py.hanzi2pinyin_split(string=han_item, split=" ")
            for x in item_pinyin.split(' '):
                if x != '':
                    all_pin += x
                    first_pin += x[0]
            res_pin = item_pinyin + ' ' + all_pin + ' ' + first_pin
            self.lis[i][3] = res_pin

    def do_search(self, key):
        result_lis = []
        for item in self.lis:
            # 将单词变为low 方便索引
            if item[0].lower().find(key) != -1 or item[0].lower().find(key.lower()) != -1\
                    or item[1].lower().find(key) != -1 \
                    or item[3].find(key) != -1:
                result_lis.append(item)
        # 按照时间进行排序
        search_result = sorted(result_lis, key=lambda x: x[2], reverse=True)
        return [x[:2] for x in search_result]