class DictionaryManager(object):
    '''
    Manage the Dutch dictionary
    '''

    def __init__(self):
        config = DBManager.get_config('puzzle')
        self.db = DBManager(config)

    def is_valid_word(self, input_word):
        '''Verify if the input text belongs to Dutch language'''
        sql = '''SELECT word FROM stripped WHERE word = '{}' LIMIT 1'''.format(input_word)
        r = self.db.fetch_as_array(sql, col=0)
        if not r:
            return False
        else:
            return True

    def words_with_pattern(self, input_word, exists=False):
        '''Return all words with the given pattern.

        Inputs
        ------
        pattern: word with periods as jokers.
        exists: flag indicating whether to check if a word merely has to exist.

        Returns
        -------
        If exists == False: List of words that match the input pattern. Words are capitalized.
        If exists == True: Boolean to indicate if a word with the given input pattern exists.

        Example
        -------
        >>> words_with_pattern('u.tge...en')
        >>> ['UITGEBETEN', 'UITGEBOGEN', 'UITGEGETEN', 'UITGEGETEN', 'UITGEGOTEN',
             'UITGEKOMEN', 'UITGEKOZEN', 'UITGELADEN', 'UITGELOPEN', 'UITGEMALEN',
             'UITGENEPEN', 'UITGEREDEN', 'UITGEREZEN', 'UITGEVAREN', 'UITGEWEKEN',
             'UITGEWEZEN', 'UITGEWOGEN', 'UITGEZETEN', 'UITGEZOGEN', 'UITGEZOPEN']
        '''
        selection = dict()
        for i, input_char in enumerate(input_word):
            if input_char != '.':
                field = 'letter{:02d}'.format(i + 1)
                selection[field] = input_char.upper()
        field = 'letter{:02d}'.format(i + 2)
        selection[field] = ''
        selection_sql = SqlHelper.criteria_dict_to_selection_sql(selection)

        sql = 'SELECT word FROM by_letter WHERE {}'.format(selection_sql)

        if exists:
            sql += ' LIMIT 1'
            r = self.db.fetch_as_array(sql)
            if not r:
                return False
            else:
                return True
        else:
            r = self.db.fetch_as_array(sql)
            return r
Example #2
0
def db_check(pk, lock):
    winner = False
    winners = ""
    # if this is a list of arrays, check for all possible addresses
    if isinstance(pk, list):
        addresses = []
        match_column = []
        # Hack to get queries correct.
        # TODO: REMOVE THIS HACK WHEN ENSURE_QUOTED IS FIXED.
        for i in range(0, len(pk)):
            addresses.append(pk[i].public_key.uncompressed_address.
                             address if i == 0 else "'" +
                             pk[i].public_key.uncompressed_address.address +
                             "'")
            addresses.append("'" +
                             pk[i].public_key.compressed_address.address + "'")
            match_column.append('address')
            match_column.append('address')
        # Check all addresses in one sweep.
        db = DBManager(debug=False)
        result = db.query_builder(sql_type="select",
                                  table="addresses",
                                  selects="aid",
                                  match_columns=match_column,
                                  matches=addresses,
                                  match_type="OR")
        # If we have a winner... print all private keys into winner file
        if result is not None and len(result) > 0:
            for key in pk:
                winners = winners + key.private_key + "\n"
            winner = True
    else:
        if pk.public_key.uncompressed_address.check_address() is not None:
            winner = True
            winners = pk.private_key
        if pk.public_key.compressed_address.check_address() is not None:
            winner = True
            winners = pk.private_key
    # If there is a winner... pop champagne and shiet.
    if winner:
        # multi_printer(msg=winners, lock=lock)
        multi_file_operations(FileOperationRequest(filename="winners",
                                                   msg=winners),
                              lock=lock)
        # pk.public_key.push_public_key()
        # pk.pub_id = pk.public_key.check_public_key()
        # pk.push_private_key()
        return True
    return False
Example #3
0
    def callback(self, ch, method, properties, body):
        msg = Message.Message().initFromJson(body)

        print('Recieved incoming message')
        print('Input File Name: ' + msg.dataSource)
        print('Input Type: ' + msg.input)
        print('Output Type: ' + msg.output)

        if msg.input != "StopConsuming":
            IncomingMessageHandler.IncomingMessageHandler().HandleMessage(
                msg.dataSource, msg.input, msg.output)
        else:
            print('*** consumer ending *** ')
            DBManager.closeConnections()
            ch.stop_consuming()
Example #4
0
 def __init__(self, **kwargs):
     Handler.__init__(self)
     name = kwargs['name'] if 'name' in kwargs else 'xgxx_log'
     if name in qyxx_dict:
         self.db_name = "qyxx_log"
     else:
         self.db_name = "xgxx_log"
     types, queue, port, host = config['type'], self.db_name, config[
         'port'], config['host']
     try:
         self.__db = DBManager.getInstance(types,
                                           queue,
                                           host=host,
                                           port=port)
     except Exception as e1:
         pass
Example #5
0
#
# NB : this is not secure
# from http://code.activestate.com/recipes/266586-simple-xor-keyword-encryption/
# added base64 encoding for simple querystring :)
#


def xor_encrypt(data, key):
    return base64.b64encode(
        bytearray(a ^ b for a, b in zip(
            *map(bytearray, [data.encode(), key.encode()])))).decode('utf-8')


app = Flask(__name__)
dbc = DBManager(dbn=DB_DATABASE)


@app.route('/', methods=['POST', 'GET'])
def main():
    dataReceive = {}
    try:
        dataReceive = request.get_json()
    except Exception as e:
        print(e)
        pass
    msgType = dataReceive['type']
    if msgType == 'register':
        return Register(dataReceive)
    elif msgType == 'login':
        return Login(dataReceive)
Example #6
0
class TaobaoScrapyPipeline(object):
    dbmanager = DBManager()
    # fil = open('t.txt', mode='w')
    #
    category_file = open('category.txt', mode='w')

    # items_file = open('items.txt', mode='w')
    def process_item(self, item, spider):
        # print('piplelines accept data :{}'.format(type(item)))
        if isinstance(item, TaobaoCategoryItem):
            category_name = item['category_name']
            category_url = item['category_url']
            insert_date = item['insert_date']
            self.category_file.write(
                'category_name:{} url:{} insert_date:{}\n'.format(
                    category_name, category_url, insert_date))
            print('处理商品一级分类')
        elif isinstance(item, TaoBaolistsrpItem):
            self.process_taobao_item(TYPE_LISTSRP, item)

        elif isinstance(item, TaoBaospulistItem):
            self.process_taobao_item(TYPE_SPULIST, item)

        elif isinstance(item, TaoBaomainsrpItem):
            self.process_taobao_item(TYPE_MAINSRP, item)

        elif isinstance(item, TaoBaospudetailItem):
            self.process_taobao_item(TYPE_SPUDETAIL, item)

    def process_taobao_item(self, type, item):
        category_name = item['category_name']
        category_url = item['category_url']
        insert_date = item['insert_date']
        request_url = item['request_url']
        page_name = item['page_name']
        data_info = item['data_info']
        data_list = item['data_list']

        data_info_insert = {
            'category_name': category_name,
            'category_url': category_url,
            'page_name': page_name,
            'category_info': data_info,
            'request_url': request_url,
            'insert_time': insert_date
        }
        # print('接受到数据:{}'.format(item))
        # return
        if type == TYPE_LISTSRP:
            for data_item in data_list:
                data_item['category_name'] = category_name
                data_item['category_url'] = category_url
                data_item['insert_time'] = datetime.now()
                data_item['_id'] = data_item.get('nid')
            self.dbmanager.insert_category_info(data_info_insert)
            self.dbmanager.insert_data_list(data_list)
        elif type == TYPE_MAINSRP:
            self.dbmanager.insert_category_info(data_info_insert)
            self.dbmanager.insert_data_list(data_list)
        elif type == TYPE_SPULIST:
            for data_item in data_list:
                data_item['category_name'] = category_name
                data_item['category_url'] = category_url
                data_item['insert_time'] = datetime.now()
            self.dbmanager.insert_category_info(data_info_insert)
            self.dbmanager.insert_spu_list(data_list)
        elif type == TYPE_SPUDETAIL:
            category_name_level_2 = item['category_name_level_2']
            data_info_insert['category_name_level_2'] = category_name_level_2
            for data_item in data_list:
                data_item['category_name'] = category_name
                data_item['category_url'] = category_url
                data_item['insert_time'] = datetime.now()
                data_item['_id'] = data_item.get('nid')
                data_item['category_name_level_2'] = category_name_level_2
            self.dbmanager.insert_category_info(data_info_insert)
            self.dbmanager.insert_data_list(data_list)
        print('type:{} 数据处理完毕'.format(type))
 def __init__(self):
     config = DBManager.get_config('puzzle')
     self.db = DBManager(config)