Example #1
0
def filtering(comments, keywords):
    block = Block()

    # 개인 키워드 기반 적절성 유무 판단
    block = Block()
    if keywords:
        comments = block.privateKeywordMatch(comments, keywords)  # 딕셔너리 리스트 받음
    # 부적절한 댓글 가리기
    conceal_bad_comment(comments)
    return comments
Example #2
0
    def add_block(self, last_block, data):
        #新增区块
        block = Block(last_block.index + 1, date.datetime.now(), data,
                      last_block.hash)

        self.chain.append(block)

        last_block = self.chain[-1]
        return last_block
Example #3
0
    def add_block(self, last_block, target_hash, nonce, data):

        block = Block(last_block.index + 1, target_hash, nonce,
                      date.datetime.now(), data, last_block.hash)

        self.chain.append(block)

        # Return last block in the chain
        return self.chain[-1]
Example #4
0
    def block_from_other_node(self, prev_block, index, timestamp, target_hash,
                              nonce, data, block_hash):

        block = Block(index, target_hash, nonce, timestamp, data,
                      prev_block.hash, block_hash)

        self.chain.append(block)

        last_block = self.chain[-1]

        return last_block
Example #5
0
def create_genesis_block():
    m = hashlib.sha256()

    timestamp = date.datetime.now()
    m.update(
        str(timestamp).encode('ascii') +
        str(random.randint(0x008000, 0x7FFFFF)).encode('ascii'))
    target_hash = m.hexdigest()

    block = Block(0, target_hash, 0, date.datetime.now(), {
        'proof-of-work': None,
        'transactions': None
    }, '0')

    return block
Example #6
0
def proof_of_work(target_hash):
    nonce = 0

    while (1):

        block = Block(0, target_hash, nonce, date.datetime.now(), {
            'proof-of-work': None,
            'transactions': None
        }, '0')

        nonce += 1

        if (int(block.hash, 16) < int(target_hash, 16)):
            proof = block
            break

    return proof
Example #7
0
    def load_chain_from_list(self, block_chain_list):
        # Empty existing chain
        self.chain[:] = []

        chain_len = len(block_chain_list)
        #print(block_chain_list)

        for i in range(0, chain_len):
            block = Block(block_chain_list[i]['index'],
                          block_chain_list[i]['target_hash'],
                          block_chain_list[i]['nonce'],
                          block_chain_list[i]['timestamp'],
                          block_chain_list[i]['data'],
                          block_chain_list[i]['previous_hash'],
                          block_chain_list[i]['hash'])

            #print(block_chain_list[i]['hash'])
            self.chain.append(block)
Example #8
0
def create_genesis_block():
    #创建创世块的信息
    block = Block(0, date.datetime.now(), 'This is Genesis block', '0')
    return block
Example #9
0
def filter():
    block = Block()
    comment = request.args.get('comment')
    result = block.runBlockComment(comment)

    return str(result)
Example #10
0
def properness_judge(new_comment):
    block = Block()
    result = block.runBlockComment(new_comment['comment'])
    print("적절성 : " + result)
    new_comment['property'] = result