Exemple #1
0
def split_case_info(case):
    title = case['title']
    content = json.loads(case['content'])
    title_list = list(jieba.cut_for_search(title))
    content_list = list(jieba.cut_for_search(content))

    case_list = title_list + content_list
    case_word_list = list(set(case_list))

    # print(case_list)
    for word in case_word_list:
        if word not in strip_word_list:
            word_md5 = common.get_md5(word)
            res = Data.find('case_search_index',
                            [('case_id', '=', case['id']),
                             ('keyword_md5', '=', word_md5)])
            if res != None:
                # print('已经存在')
                continue
            params = {
                'case_id': case['id'],
                'keyword': json.dumps(word),
                'keyword_md5': word_md5
            }
            Data.insert('case_search_index', params)
            continue
        else:
            continue
Exemple #2
0
    def insert(self,table,content):
        Data.insert(table,content)
        if table in self.data_all:
            self.append_lines(table)
        else:
            self.refresh_one_table(table)

        return
Exemple #3
0
    def refresh_db(self):

        time_now = time_to_str(int(time.time())).split()[1].split(':')[:2]
        if ':'.join(time_now) == refresh_time:
            for table in self.data_all:
                Data.delete(table,[])
                Data.insert(table,self.data_all[table])
            time.sleep(60)
        else:
            pass
        return
Exemple #4
0
    def write_event_post_item(self, data, res):
        for item in data['post_items']:
            item_url = self.get_post_item(item)
            params = {
                'case_id': res['id'],
                'post_item': item_url,
                'ctime': int(time.time()),
                'raw_url': item,
            }

            Data.insert('case_post_item', params)
Exemple #5
0
    def get(self):
        data = self.get_data()

        if data['pw1'] != data['pw2']:
            self.send_faild('PW_NOT_SAME')
            return

        if data['invite_token'] == '':
            self.send_faild('NO_TOKEN')
            return
        # 需要传入邀请者token作为参数

        res = Data.find('user', [('user_name', '=', data['username'])])
        if res != None:
            self.send_faild('ACCOUNT_HAD')
            return

        inviter = Data.find('user', [('token', '=', data['invite_token'])])
        if inviter == None:
            self.send_faild('NO_TOKEN')
            return

        params = {
            'user_name': data['username'],
            'passwd': common.get_md5(data['pw2']),
            'join_time': int(time.time()),
            'uuid': self.create_uuid(),
            'invite_id': inviter['id'],
            'nickname': json.dumps(data['nickname'])
        }

        Data.insert('user', params)
        Data.update('user', [('id', '=', inviter['id'])], {'token': ''})
        # 插入新的数据,为了安全,更新一次token

        conditions = [('user_name', '=', data['username']),
                      ('passwd', '=', common.get_md5(data['pw2']))]

        res = Data.find('user', conditions)
        token = self.get_token(res)

        result = {'token': token}

        Data.update('user', conditions, result)
        # 插入token

        self.send_ok(result)
        return
Exemple #6
0
    def post(self):
        data = self.get_post_data()
        user_base = self.get_user_base()

        content = json.dumps(data['content'])
        # content = content.replace('\\','\\\\') # 不确定是否需要
        content_md5 = common.get_md5(content)

        user_id = user_base['id']
        ctime = int(time.time())
        event_time = common.str_to_time(data['event_time'] + ' 00:00:00')
        title = data['title']

        # Data.find('case_info',[('content_md5','=',content_md5)])

        params = {
            'user_id': user_id,
            'ctime': ctime,
            'content': content,
            'content_md5': content_md5,
            'event_time': event_time,
            'title': title,
        }

        Data.insert('case_info', params)
        # self.write_event_post_item()

        cond = [('user_id', '=', user_id), ('ctime', '=', ctime),
                ('content_md5', '=', content_md5)]

        res = Data.find('case_info', cond)
        self.split_case_info(res)
        # 创建关键词索引

        # self.write_event_post_item(data,res)

        if res != None:
            self.send_ok({})
            self.write_event_post_item(data, res)
            print('download_done!')
            return
        else:
            self.send_faild({'INSERT_FAIL'})
            return
Exemple #7
0
def write_main_info():
    title = '南昌红谷滩杀人'

    content = '''32岁南昌男子从背后袭击,当街将24岁女子捅杀】24日下午5时18分许,南昌市红谷滩发生一起杀人案。27日记者从南昌公安局了解到,犯罪嫌疑人万某弟(男,32岁,南昌人)已被控制,作案动机仍在调查。监控视频显示,行凶者当时冲向并排行走的三人,持刀向其中一名女子砍去。女子倒地后,行凶者仍不依不饶。另据@北京时间 报道,凶手曾想杀“个子高”女子,后发现另一女子“更白更漂亮”。'''

    content = json.dumps(content)  #.replace('\\','\\\\')
    content_md5 = common.get_md5(content)

    event_time = '2019-05-28 00:00:00'
    event_time = common.str_to_time(event_time)

    params = {
        'user_id': 2,
        'ctime': int(time.time()),
        'content': content,
        'content_md5': content_md5,
        'event_time': event_time,
        'title': title
    }
    # Data.update('case_info',[('content_md5','=',content_md5)],params)
    Data.insert('case_info', params)