Exemple #1
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 #2
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
    def get_token(self, res):

        # 生成该用户的token

        uuid_string = str(res['uuid'])
        user_id_string = str(res['id'])
        username_string = str(res['user_name'])
        time_string = str(int(time.time()))

        token = common.get_md5(uuid_string + user_id_string + username_string +
                               time_string)

        return token
Exemple #4
0
    def get(self):
        data = self.get_data()
        pw_md5 = common.get_md5(data['pw'])
        condition = [('user_name', '=', data['username']),
                     ('passwd', '=', pw_md5)]

        res = Data.find('user', condition)
        if res == None:
            self.send_faild('LOGIN_PSW_ERROR')
            return
        else:
            token = self.get_token(res)
            result = {'token': token}
            Data.update('user', condition, result)

            self.send_ok(result)
            return
Exemple #5
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 #6
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)
Exemple #7
0
    def get_post_item(self, item_url):
        file_tail = item_url.split('/')[-1].split('.')[-1]

        if file_tail in SERVER['file_name']:
            # 图片文件
            r = requests.get(item_url)
            content = str(r.content)
            file_name = common.get_md5(content)

            running_path = os.path.abspath('..')
            path = running_path.split('/')
            client_path = path[:-2]
            client_path.append('client/web_index/post_items/')

            client_path = '/'.join(client_path)

            open(client_path + file_name + '.' + file_tail,
                 'wb').write(r.content)
            item_url = SERVER['URL'] + file_name + '.' + file_tail

        return item_url
Exemple #8
0
    def get(self):
        data = self.get_data()
        keyword_list = data['keyword_list']

        if keyword_list == []:
            self.send_faild('NEED_WORD')
            return

        case_id_list = []

        for keyword in keyword_list:
            keyword_md5 = common.get_md5(keyword)
            res = Data.select('case_search_index',
                              [('keyword_md5', '=', keyword_md5)])
            if res == None:
                continue
            else:
                for case in res:
                    case_id_list.append(case['case_id'])
                continue

        case_id_list = list(set(case_id_list))
        print(case_id_list)

        title_list = []

        for case_id in case_id_list:
            res = Data.find('case_info', [('id', '=', case_id)])
            if res == None:
                continue
            else:
                case_info = {'case_id': res['id'], 'title': res['title']}
                title_list.append(case_info)
                continue

        result = {'keyword_list': keyword_list, 'result': title_list}
        # 关键词搜索

        self.send_ok(result)
        return