Exemple #1
0
 def set_players(self, color_current_user):
     self.player1 = Player(color_current_user, True)
     color_player2 = 'white' if color_current_user == 'black' else 'black'
     if not self.with_bot:
         self.player2 = Player(color_player2)
     else:
         self.player2 = Bot(color_player2)
Exemple #2
0
def receive():
    bot = Bot()
    content = request.json

    response = bot.receive_message(content["id"], content["name"],
                                   content["answer"])

    return response
    def __init__(self):
        self.whatsapp = None

        self.bot = Bot()

        self.log_web = []
        self.log_info = {}

        self.init()
Exemple #4
0
 def event(cls, event: vk_api.longpoll.Event, api):
     if event.type in Method.methods_by_code:
         return [
             method.func(Bot(api, event)) for method in filter(
                 lambda m: type(m.func) == func_type and
                 (Permission.have_access(m.permission, event.user_id) or
                  event.from_me) and m.req(event), Method.methods_by_code[
                      event.type])
         ]
     return []
Exemple #5
0
def prompt():

    questions = [
        inquirer.Text(name="ads_id",
                      message="Elanın İD nömrəsini yazın",
                      validate=lambda _, x: str(x).isnumeric())
    ]
    answers = inquirer.prompt(questions)

    try:
        crawler = Crawler(answers['ads_id'])
        info = crawler.get_info()
        bot = Bot(info)
        bot.send()
    except Exception as err:
        print(err)
Exemple #6
0
def main():
    sync = Sync()
    service = Service()
    scrapper = Scrapper()
    cadastros = sync.carrega_todos_os_cadastros()

    for cadastro in cadastros:
        # Busca e atualiza o preço médio do boardgame
        service_result = service.busca_preco_medio(cadastro['boardgame'])
        sync.atualiza_preco_medio(cadastro, service_result['preco'])
        if not service_result['preco']:
            continue

        # Faz o scrap no ludopedia para buscar anúncios deste produto
        resultado_scrapper = scrapper.scrap_anuncios(cadastro['boardgame'])

        # Compara os preços para ver se precisa ou não notificar o usuário
        itens_para_notificar = filtra_itens_abaixo_do_preco(
            service_result['preco'], resultado_scrapper)

        if len(itens_para_notificar) == 0:
            continue

        bot = Bot()
        for item in itens_para_notificar:
            mensagem = (
                "** ITEM ABAIXO DO PREÇO **\n\n"
                f"O item '{cadastro['boardgame'].upper()}' possui preço médio de R$ {service_result['preco']}\n"
                f"Encontramos o(s) seguinte(s) anúncio(s) abaixo do preço médio:\n"
                "- Categoria: {}\n- Preço: {}\n- Link: {}".format(
                    item.get('category'),
                    item.get('value'),
                    item.get('link')
                )
            )
            bot.enviar_notificacao(cadastro['chat_id'], mensagem)
 def start(self):
     while True:
         print(Bot().dispatcher.get_me())
         sleep(1)
Exemple #8
0
if __name__=='__main__':
	if sys.version_info[:2]<(3,6):
		print('You need at least Python3.6 to run this program.')
		sys.exit(1)
	supported_browsers=['chrome','firefox']
	parser=ArgumentParser()
	parser.add_argument('-u','--url',help='Set URL | Set path to URL list',metavar='URL|FILE')
	parser.add_argument('-p','--processes',default=15,type=int,help='Set number of processes',metavar='N')
	parser.add_argument('-B','--browser',choices=supported_browsers,help='Set browser',metavar='BROWSER')
	parser.add_argument('-P','--proxies',help='Set path to proxy list',metavar='FILE')
	parser.add_argument('-R','--referer',help='Set referer | Set path to referer list',metavar='REFERER|FILE')
	parser.add_argument('-U','--user-agent',help='Set user agent | Set path to user agent list',metavar='USER_AGENT|FILE')
	args=parser.parse_args()
	urls=URLs(args.url or Input.get('URL'))
	browser=args.browser or Input.select('Browser',supported_browsers)
	print('Click ENTER to use default value.')
	proxies=Proxies(Input.get('Proxies') or args.proxies)
	referers=Referers(Input.get('Referers') or args.referer)
	user_agents=UserAgents(Input.get('User agents') or args.user_agent)
	executable_path=WebDriver.install_if_not_installed(browser)
	extension_path=Extension.install_if_not_installed(browser)
	processes=[Process(target=Bot().run,args=(urls,browser,proxies,referers,user_agents,executable_path,extension_path),daemon=True) for _ in range(args.processes)]
	for process in processes:
		process.start()
	signal.signal(signal.SIGINT,signal.SIG_IGN)
	for process in processes:
		process.join()
	if WebDriver.system=='Windows':
		os.system(f'taskkill /IM {browser}.exe /T /F >NUL 2>&1')
	sys.exit(0)
Exemple #9
0
from modules.bot import Bot

if __name__ == '__main__':
    bot = Bot()
    bot.set_webhook()
def main():
    telegram_bot = Bot()
    telegram_bot.listen()
Exemple #11
0
def main():
    bot = Bot()
    bot.run()
Exemple #12
0
    def __init__(self):
        # create default personalities
        cm = Character_Manager()
        cm.save("character_default")
        cm.save("character_stable")
        cm.save("character_empathetic")
        cm.save("character_irascible")

        # set up logging
        logging.basicConfig(
            level=logging.INFO,
            filename='../logs/app.log',
            filemode="w",
            format='%(asctime)s %(name)s/%(levelname)s - - %(message)s',
            datefmt='%d.%m.%y %H:%M:%S')
        self.logger = logging.getLogger("controller")
        self.logger.setLevel(logging.INFO)

        # read config file and save values in variables
        self.config = configparser.ConfigParser()
        self.config.read("../config/config.ini")
        self.botname = self.config.get("default", "botname")
        self.username = self.config.get("default", "username")
        self.classifier_data = [
            self.config.get("net", "classifier_type"),
            self.config.get("net", "dataset"),
            self.config.get("net", "feature_set")
        ]
        self.logger.info("Conifg loaded: {}, {}, {}".format(
            self.botname, self.username, self.classifier_data))

        # initialize emotional variables
        self.lex_happiness = pd.read_csv("../lexica/clean_happiness.csv",
                                         delimiter=",",
                                         dtype={
                                             "text": str,
                                             "affect": str,
                                             "stems": str
                                         },
                                         float_precision='round_trip')
        self.lex_sadness = pd.read_csv("../lexica/clean_sadness.csv",
                                       delimiter=",",
                                       dtype={
                                           "text": str,
                                           "affect": str,
                                           "stems": str
                                       },
                                       float_precision='round_trip')
        self.lex_anger = pd.read_csv("../lexica/clean_anger.csv",
                                     delimiter=",",
                                     dtype={
                                         "text": str,
                                         "affect": str,
                                         "stems": str
                                     },
                                     float_precision='round_trip')
        self.lex_fear = pd.read_csv("../lexica/clean_fear.csv",
                                    delimiter=",",
                                    dtype={
                                        "text": str,
                                        "affect": str,
                                        "stems": str
                                    },
                                    float_precision='round_trip')
        self.LIST_OF_LEXICA = self.lex_happiness, self.lex_sadness, self.lex_anger, self.lex_fear
        self.list_happiness = self.lex_happiness["stems"].tolist()
        self.list_sadness = self.lex_sadness["stems"].tolist()
        self.list_anger = pd.Series(self.lex_anger["stems"].tolist())
        self.list_fear = self.lex_fear["stems"].tolist()
        self.lex_happiness_adj = pd.read_csv(
            "../lexica/clean_happiness_adj.csv",
            delimiter=",",
            dtype={
                "text": str,
                "intensity": float
            },
            float_precision='round_trip')
        self.lex_sadness_adj = pd.read_csv("../lexica/clean_happiness_adj.csv",
                                           delimiter=",",
                                           dtype={
                                               "text": str,
                                               "intensity": float
                                           },
                                           float_precision='round_trip')
        self.lex_anger_adj = pd.read_csv("../lexica/clean_happiness_adj.csv",
                                         delimiter=",",
                                         dtype={
                                             "text": str,
                                             "intensity": float
                                         },
                                         float_precision='round_trip')
        self.lex_fear_adj = pd.read_csv("../lexica/clean_happiness_adj.csv",
                                        delimiter=",",
                                        dtype={
                                            "text": str,
                                            "intensity": float
                                        },
                                        float_precision='round_trip')
        self.logger.info("Lexica loaded")

        # initialize ml-variables
        if self.config.getboolean("default", "firstlaunch"):
            # das md-model ist ca 80mb, das lg ca 1g
            # self.nlp = spacy.load("en_core_web_lg")
            self.nlp = spacy.load("en_core_web_md")
        else:
            self.nlp = spacy.load("../models/spacy")
        self.spell = SpellChecker()

        # create bot, responsible for generating answers and classifier, for analysing the input
        self.character = Character(
            self.config.getboolean("default", "firstlaunch"))
        self.classifier = Classifier(self.classifier_data, self.LIST_OF_LEXICA,
                                     self.nlp)
        self.bot = Bot(self.lex_happiness, self.lex_sadness, self.lex_anger,
                       self.lex_fear, self.list_happiness, self.list_sadness,
                       self.list_anger, self.list_fear, self.lex_happiness_adj,
                       self.lex_sadness_adj, self.lex_anger_adj,
                       self.lex_fear_adj, self.nlp)
        if self.config.getboolean("default", "firstlaunch"): self.bot.train()

        # create frame and update widgets with initial values
        self.frame = Frame(self.botname, self.character.get_emotional_state(),
                           self.character.get_emotional_history())
        self.frame.register_subscriber(self)
        self.frame.show()

        # save all session data after the frame is closed
        self.save_session()
        logging.shutdown()
Exemple #13
0
def restart():
    bot = Bot()
    bot.restart()

    return 'restarted'
Exemple #14
0
def export():
    bot = Bot()
    bot.export_results()

    return 'exported'