Esempio n. 1
0
    def test_create(self):
        """Test basic functionality of SimpleBot remains up-to-date with _models."""
        simple_bot = chatbot.SimpleBot(dataset=self.dataset,
                                       params=self.config)
        self.assertIsInstance(simple_bot, chatbot.SimpleBot)

        chat_bot = chatbot.ChatBot(buckets=[(10, 10)],
                                   dataset=self.dataset,
                                   params=self.config)
        self.assertIsInstance(chat_bot, chatbot.ChatBot)
Esempio n. 2
0
def get_data(usr, request_user_id):
    if isinstance(usr.user_status, bool):
        pass
    elif isinstance(usr.user_status[0], list):
        x = chatbot.ChatBot()
        if 'bdate' in usr.user_status[0]:
            usr.age = int(x.requests_data('bdate', request_user_id))
        if 'city' in usr.user_status[0]:
            usr.city = usr.get_city(x.requests_data('city', request_user_id))
        if 'sex' in usr.user_status[0]:
            user_sex = int(x.requests_data('sex', request_user_id))
            usr.sex = 2 if (user_sex == 1) else 1
        usr.user_status = usr.user_status[1]
Esempio n. 3
0
def main():
    x = chatbot.ChatBot()
    get = x.search()
    if get:
        session = db.Session()
        if isinstance(get[0], int):
            db_user = session.query(db.User).filter_by(user_id=get[0]).first()
        else:
            db_user = session.query(db.User).filter_by(domain=get[0]).first()
        if not db_user:
            user = vkuser.VKUser(get[0], get[1], 0)
            get_data(user, get[1])
            db_user = db_insert_user(user, session, get[1])
        else:
            user = vkuser.VKUser(db_user.user_id,
                                 db_user.request_user_id,
                                 db_user.offset,
                                 new_user=False)
            user.domain = db_user.domain
            user.first_name = db_user.first_name
            user.last_name = db_user.last_name
            user.user_status = db_user.user_status
            user.sex = db_user.sex
            user.age = db_user.age
            user.city = db_user.city
        result = []
        while len(result) < 10:
            response = user.__next__()
            if response is None:
                continue
            elif len(response) == 0:
                continue
            for item in response:
                check = session.query(db.Match).filter_by(match_id=db_user.id).filter_by(user_id=item['id']).first()
                if check:
                    continue
                elif item['is_closed']:
                    continue
                photo = user.get_profile_photos(item['id'])
                result.append(('https://vk.com/' + item['domain'], photo))
                db_insert_match(db_user, session, item, photo)
        db_user.offset = user.offset
        session.add(db_user)
        session.commit()
        for i in result:
            photos = [photo['sizes']['url'] for photo in i[1]]
            x.attach_image(db_user.request_user_id, photos, i[0])
        with open('result.json', 'w') as outfile:
            dump(result, outfile)
Esempio n. 4
0
    def test_compile(self):
        """Test basic functionality of SimpleBot remains up-to-date with _models."""
        buckets = [(10, 20)]

        # SimpleBot
        logging.info("Creating/compiling SimpleBot . . . ")
        bot = chatbot.SimpleBot(dataset=self.dataset, params=self.config)
        bot.compile()

        # ChatBot
        logging.info("Creating/compiling ChatBot . . . ")
        bot = chatbot.ChatBot(buckets=buckets,
                              dataset=self.dataset,
                              params=self.config)
        bot.compile()
Esempio n. 5
0
# -*- coding: utf-8 -*-
import os
import cgi
import sys
import json
import jieba
import chatbot
import logging
import SocketServer
import SimpleHTTPServer

# 新建机器人
idx = 0
bot = chatbot.ChatBot("qifeng")


def load_userdict():
    """
    Load user dictionary
    """
    # 姓名列表
    jieba.load_userdict("./dict/name/amuse.txt")
    jieba.load_userdict("./dict/name/sporter.txt")
    jieba.load_userdict("./dict/name/politicians.txt")

    # 体育项目
    jieba.load_userdict("./dict/sport.txt")
    # 体育项目

    # 默认词典
    jieba.load_userdict("./dict/dict.txt")
Esempio n. 6
0
 def __init__(self):
     print("create gui started.")
     self.chatbot_inst = cb.ChatBot()
     self.__create()
Esempio n. 7
0
def get_bot_response():
    userAnswer = request.args.get('msg')
    chat = mymodule.ChatBot(userAnswer)
    return str(chat.check_answer())