def callback_query(call): bot.answer_callback_query(call.id) bot.delete_message(call.message.chat.id, call.message.id) if is_reg(call.message): analytics_manager(call.data, users_dict[call.message.chat.id]) else: bot.send_message(call.message.chat.id, "Please /start again")
def callback_query(call): bot.answer_callback_query(call.id) if is_reg(call.message): bot.delete_message(call.message.chat.id, call.message.id) bot.send_message(call.message.chat.id, "Please click /hi again") else: bot.send_message(call.message.chat.id, "Please /start again")
def enable_analytics(message, user): if user.flags['analytics_enabled']: yes_msg = "You have analytics enabled.\n\n Analytics do not share anything and does not even have any open api " \ "to access any records, as aviral dont provide any analytics so we have" \ + "to maintain our own little DB to give you analytics. It is not shared and all the code is hosted " \ "on " \ "github so you can ensure that there is no API support for any privacy" \ + " invading calls." msg = bot.send_message(message.chat.id, yes_msg) # time.sleep(10) # bot.delete_message(message.chat.id, msg.id) yes_msg = "But still if you dont want to contribute to rank analytics then it okay too. You can opt out from " \ "here. You can still use ZeNo as before but without analytics. \n\n" yes_msg += "Here are some things to keep in mind when opting out.\n" \ + "1. You wont be able to see your ranks also.\n" \ + "2. Your old data will take time to flush out from system but your new marks will not be stored " \ "from immediate effect.\n" \ + "3. As of now you can't opt in one you opt out.\n\n\n\n Please wait......" msg1 = bot.send_message(message.chat.id, yes_msg) time.sleep(10) bot.delete_message(message.chat.id, msg.id) bot.delete_message(message.chat.id, msg1.id) markup = InlineKeyboardMarkup() markup.row_width = 2 markup.add(InlineKeyboardButton("Disable Analytics for me", callback_data="enable_analytics_no"), InlineKeyboardButton("Cancel", callback_data="cancel")) bot.send_message(message.chat.id, "Do you want to opt out?", reply_markup=markup) else: markup = InlineKeyboardMarkup() markup.row_width = 2 markup.add(InlineKeyboardButton("Enable Analytics for me", callback_data="enable_analytics_yes"), InlineKeyboardButton("Cancel", callback_data="cancel")) bot.send_message(message.chat.id, "Do you want to opt in?", reply_markup=markup)
def get_marks(message, user, session): bot.delete_message(message.chat.id, message.id) wait_msg_cont = "Getting marks for " + session + " Session...." + "\n\n" wait_msg = bot.send_message(message.chat.id, wait_msg_cont, parse_mode="MarkDown") header_auth['session'] = session header_auth['Authorization'] = user.jwt_token header_auth['X-CSRFToken'] = user.cs_token god_draft = None try: user_marks = requests.get(aviral_marks_api, headers=header_auth) user_data = requests.get(aviral_details_api, headers=header_auth) user_sem_data = requests.get(aviral_semester_result_api, headers=header_auth) god_draft = json.loads(user_marks.text) marks = "\nNo Results for this session.." try: sgpi = Parser.sgpi_parser(user_sem_data.json(), session, analytics=user.flags['analytics_enabled']) marks = Parser.marks_parser(god_draft, user.username, session, analytics=user.flags['analytics_enabled']) cgpi = Parser.cgpi_parser(user_data.json(), session, analytics=user.flags['analytics_enabled']) except: sgpi = "error parsing sgpi" print("issue in getting sgpi api") bot.send_message(message.chat.id, marks, parse_mode="MarkDown") if marks != "\nNo Results for this session..": bot.send_message(message.chat.id, sgpi, parse_mode="MarkDown") bot.send_message(message.chat.id, cgpi, parse_mode="MarkDown") if user.flags['analytics_enabled']: save_marks(user, session, god_draft) except Exception as e: print(str(e)) bot.send_message(message.chat.id, "something went wrong!!! please /start again") del users_dict[message.chat.id] user.del_user_db() bot.delete_message(wait_msg.chat.id, wait_msg.id) return god_draft
def analytics_manager(data, user): if data == "enable_analytics_no": user.flags['analytics_enabled'] = False set_flag(user.username, "analytics_enabled", False) msg = bot.send_message(user.chat_id, "okay, Your new marks will not be used for analytics from now.") time.sleep(5) bot.delete_message(user.chat_id, msg.id) if data == "enable_analytics_yes": user.flags['analytics_enabled'] = True set_flag(user.username, "analytics_enabled", True) msg = bot.send_message(user.chat_id, "okay, but opting in and out multiple time will block the feature for you.") time.sleep(5) bot.delete_message(user.chat_id, msg.id)
def get_session(message, user): msg = bot.send_message(user.chat_id, "Getting session details.....") header_auth['Authorization'] = user.jwt_token header_auth['X-CSRFToken'] = user.cs_token header_auth['session'] = user.session try: sessions = requests.get(url=aviral_sessions_api, headers=header_auth).json() markup = InlineKeyboardMarkup() markup.row_width = 2 for i in sessions: if i["current"]: markup.add(InlineKeyboardButton(i['name'], callback_data="getmarks_" + i['session_id'])) bot.send_message(user.chat_id, "Which Session??", reply_markup=markup) except Exception as e: print("error getting session") print(str(e)) bot.send_message(user.chat_id, "error getting session details. /start again") bot.delete_message(msg.chat.id, msg.id)