async def get_questions(rubric_id: int): """ Получить вопросы в конкретной рубрике :param rubric_id: Номер рубрики :return: Список вопросов из этой рубрики """ db_worker = SQLighter("database.db") return db_worker.get_questions(rubric_id)
async def top_initiatives(): """ Получение списка инициатив :return: вернет список инициатив """ db_worker = SQLighter("database.db") initiatives = db_worker.get_initiatives() return initiatives
def bot_move(chat_id): random.seed() base = SQLighter(database_name) player = base.select_single(chat_id) if player[2] == 9: return False while True: i = random.randint(0, 2) j = random.randint(0, 2) if player[3][3 * i + j] == ' ': update_board(chat_id, i, j, False) return True
async def login(login: str, password: str): """ Логин в приложение через внутренний аккаунт :param login: Логин пользователя :param password: Пароль пользователя :return: результат логина """ db_worker = SQLighter("database.db") is_registred = db_worker.get_user(login, password) result = {"registred": is_registred} db_worker.close() return result
def create_markup(chat_id): base = SQLighter(database_name) player = base.select_single(chat_id) board = transform_board(player[3]) keyboard = types.InlineKeyboardMarkup() keyboard.row_width = 3 for i in range(0, 3): keyboard.add( types.InlineKeyboardButton(text=board[i][0], callback_data=str(i) + '0'), types.InlineKeyboardButton(text=board[i][1], callback_data=str(i) + '1'), types.InlineKeyboardButton(text=board[i][2], callback_data=str(i) + '2')) return keyboard
async def read_coords(user_id: float): """ Получение списка опросов :param user_id: номер пользователя :return: список рубрик(опросов) """ db_worker = SQLighter("database.db") survey = db_worker.get_survies(user_id) result = {} for a in survey: print(a) result["name"] = a[0][0] result["description"] = a[0][1] result["rubrick_id"] = a[1] return result
def check_win(chat_id): base = SQLighter(database_name) player = base.select_single(chat_id) if ((player[3][0] != ' ' and player[3][0] == player[3][1] and player[3][1] == player[3][2]) or (player[3][3] != ' ' and player[3][3] == player[3][4] and player[3][4] == player[3][5]) or (player[3][6] != ' ' and player[3][6] == player[3][7] and player[3][7] == player[3][8]) or (player[3][0] != ' ' and player[3][0] == player[3][3] and player[3][3] == player[3][6]) or (player[3][1] != ' ' and player[3][1] == player[3][4] and player[3][4] == player[3][7]) or (player[3][2] != ' ' and player[3][2] == player[3][5] and player[3][5] == player[3][8]) or (player[3][0] != ' ' and player[3][0] == player[3][4] and player[3][4] == player[3][8]) or (player[3][2] != ' ' and player[3][2] == player[3][4] and player[3][4] == player[3][6])): return True return False
async def send_complaint(text: str, user_id: float): """ Отправка жалобы :param text: Текст жалобы :param user_id: Номер пользователя """ db_worker = SQLighter("database.db") db_worker.send_complaint(text, user_id) db_worker.close()
async def send_variant_answer(variant_id: str, question_id: int, user_id: int): """ Отправка ответа в виде варианта ответа на вопрос :param variant_id: Номер варианта ответа :param question_id: Номер вопроса :param user_id: Номер пользователяд """ db_worker = SQLighter("database.db") db_worker.send_variant_answer(variant_id, question_id, user_id) db_worker.close()
def update_board(chat_id, i, j, bot): base = SQLighter(database_name) player = base.select_single(chat_id) if player[3][3 * i + j] != ' ': return False base.update_count(chat_id, player[2] + 1) board = player[3] if player[1] == 1: board = (player[3][0:3 * i + j] if 3 * i + j > 0 else '') + ( 'X' if bot else 'O') + (player[3][3 * i + j + 1:9] if 3 * i + j < 8 else '') else: board = (player[3][0:3 * i + j] if 3 * i + j > 0 else '') + ( 'O' if bot else 'X') + (player[3][3 * i + j + 1:9] if 3 * i + j < 8 else '') base.update_board(chat_id, board) return True
async def send_free_answer(text: str, question_id: int, user_id: int): """ Отправка ответа в свободной форме на вопрос :param text: Текст ответа :param question_id: Номер вопроса :param user_id: Номер пользователя """ db_worker = SQLighter("database.db") predicter = TextModel() prediction = predicter.predict([text]) negative, positive = prediction.tolist()[0][0], prediction.tolist()[0][1] result_prediction = "POSITIVE" if positive > negative else "NEGATIVE" db_worker.send_free_answer(text, question_id, result_prediction, user_id) db_worker.close()
def callback_inline(call): if call.message: if call.data == "kids": global a a = 1 keyboard = types.InlineKeyboardMarkup() callback_button = types.InlineKeyboardButton( text="На взаимодействие", callback_data="inter") callback_button1 = types.InlineKeyboardButton( text="Уличные", callback_data="street") callback_button2 = types.InlineKeyboardButton(text="Шутки", callback_data="joke") callback_button3 = types.InlineKeyboardButton( text="На снятие напряжения", callback_data="relax") callback_button4 = types.InlineKeyboardButton( text="Быстрые", callback_data="quick") callback_button5 = types.InlineKeyboardButton( text="Тактильные", callback_data="touch") callback_button6 = types.InlineKeyboardButton(text="На знакомство", callback_data="know") keyboard.add(callback_button) keyboard.add(callback_button3) keyboard.add(callback_button1, callback_button2, callback_button4, callback_button5) keyboard.add(callback_button6) bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text="Выбери тип игры!", reply_markup=keyboard) if call.data == "keys": a = 2 keyboard = types.InlineKeyboardMarkup() callback_button = types.InlineKeyboardButton( text="На взаимодействие", callback_data="inter") callback_button1 = types.InlineKeyboardButton( text="Уличные", callback_data="street") callback_button2 = types.InlineKeyboardButton(text="Шутки", callback_data="joke") callback_button3 = types.InlineKeyboardButton( text="На снятие напряжения", callback_data="relax") callback_button4 = types.InlineKeyboardButton( text="Быстрые", callback_data="quick") callback_button5 = types.InlineKeyboardButton( text="Тактильные", callback_data="touch") callback_button6 = types.InlineKeyboardButton(text="На знакомство", callback_data="know") keyboard.add(callback_button) keyboard.add(callback_button3) keyboard.add(callback_button1, callback_button2, callback_button4, callback_button5) keyboard.add(callback_button6) bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text="Выбери тип игры!", reply_markup=keyboard) if call.data == "keep": a = 3 keyboard = types.InlineKeyboardMarkup() callback_button = types.InlineKeyboardButton( text="На взаимодействие", callback_data="inter") callback_button1 = types.InlineKeyboardButton( text="Уличные", callback_data="street") callback_button2 = types.InlineKeyboardButton(text="Шутки", callback_data="joke") callback_button3 = types.InlineKeyboardButton( text="На снятие напряжения", callback_data="relax") callback_button4 = types.InlineKeyboardButton( text="Быстрые", callback_data="quick") callback_button5 = types.InlineKeyboardButton( text="Тактильные", callback_data="touch") callback_button6 = types.InlineKeyboardButton(text="На знакомство", callback_data="know") keyboard.add(callback_button) keyboard.add(callback_button3) keyboard.add(callback_button1, callback_button2, callback_button4, callback_button5) keyboard.add(callback_button6) bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text="Выбери тип игры!", reply_markup=keyboard) if call.data == "inter": r = random.randint(1, 59) db_worker = SQLighter(config.database_name) row = db_worker.select_single_inter(r, a) bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text=row) if call.data == "street": r = random.randint(1, 59) db_worker = SQLighter(config.database_name) row = db_worker.select_single_street(r, a) bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text=row) if call.data == "joke": r = random.randint(1, 59) db_worker = SQLighter(config.database_name) row = db_worker.select_single_joke(r, a) bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text=row) if call.data == "relax": r = random.randint(1, 59) db_worker = SQLighter(config.database_name) row = db_worker.select_single_relax(r, a) bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text=row) if call.data == "quick": r = random.randint(1, 59) db_worker = SQLighter(config.database_name) row = db_worker.select_single_quick(r, a) bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text=row) if call.data == "touch": r = random.randint(1, 59) db_worker = SQLighter(config.database_name) row = db_worker.select_single_touch(r, a) bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text=row) if call.data == "know": r = random.randint(1, 59) db_worker = SQLighter(config.database_name) row = db_worker.select_single_know(r, a) bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text=row)
def clear_board(chat_id): base = SQLighter(database_name) base.update_count(chat_id, 0) base.update_board(chat_id, ' ') base.close()
class HttpProcessor(BaseHTTPRequestHandler): data = SQLighter.DB("my.db") def do_GET(self): segments = self.path.split('/') if segments[1] == 'user': self.send_response(200) set_headers(self) self.wfile.write(convert(self.data.get_user(segments[2]))) if segments[1] == 'master': self.send_response(200) set_headers(self) self.wfile.write(convert(self.data.get_master(segments[2]))) if segments[1] == 'event': self.send_response(200) set_headers(self) self.wfile.write(convert(self.data.get_event(segments[2]))) if segments[1] == 'users': self.send_response(200) set_headers(self) self.wfile.write(convert(self.data.get_users())) if segments[1] == 'masters': self.send_response(200) set_headers(self) self.wfile.write(convert(self.data.get_masters())) if segments[1] == 'events': self.send_response(200) set_headers(self) self.wfile.write(convert(self.data.get_events())) def do_DELETE(self): segments = self.path.split('/') if segments[1] == 'user': self.send_response(204) set_headers(self) self.data.del_user(segments[2]) if segments[1] == 'master': self.send_response(204) set_headers(self) self.data.del_master(segments[2]) if segments[1] == 'event': self.send_response(204) set_headers(self) self.data.del_event(segments[2]) def do_PUT(self): length = int(self.headers['content-length']) field_data = self.rfile.read(length) res_data = json.dumps(field_data.decode('utf-8')) segments = self.path.split('/') if segments[1] == 'user': self.send_response(201) set_headers(self) self.data.add_user(res_data.email, res_data.name, res_data.surname, res_data.age, res_data.phone) if segments[1] == 'master': self.send_response(201) set_headers(self) self.data.add_master(res_data.email, res_data.name, res_data.surname, res_data.age, res_data.phone, res_data.address, res_data.spec) if segments[1] == 'event': self.send_response(201) set_headers(self) self.data.add_event(res_data.user_id, res_data.master_id, res_data.time) def do_POST(self): length = int(self.headers['content-length']) field_data = self.rfile.read(length) res_data = json.dumps(field_data.decode('utf-8')) segments = self.path.split('/') if segments[1] == 'user': self.send_response(200) set_headers(self) self.data.edit_user(res_data.user_id, res_data.email, res_data.name, res_data.surname, res_data.age, res_data.phone) if segments[1] == 'master': self.send_response(200) set_headers(self) self.data.edit_master(res_data.master_id, res_data.email, res_data.name, res_data.surname, res_data.age, res_data.phone, res_data.address, res_data.spec) if segments[1] == 'event': self.send_response(200) set_headers(self) self.data.edit_event(res_data.event_id, res_data.user_id, res_data.master_id, res_data.time)
from sys import platform import SQLighter import telebot from config import token from selenium import webdriver import dota_parser_lib if __name__ == "__main__": if platform == "win32": driver = webdriver.PhantomJS('phantomjs.exe') else: try: driver = webdriver.PhantomJS() except Exception as e: print(e) driver.set_window_size(1080, 1920) bot = telebot.TeleBot(token) sqler = SQLighter.DotaSqlClient() dota_info = dota_parser_lib.info_match(sqler, bot) dota_info.give_results_live(driver) dota_info.give_results_of_matches() dota_info.give_tour_pic(driver) # В конце удаляем завершенные матчи sqler.delete_finisher_matches() print('I try to tell all results!.')
def solo_reset_all(chat_id): base = SQLighter(database_name) base.update_flag_down(chat_id) base.reset_current_bet(chat_id) base.clear_all_bets(chat_id)