def settings(): update_password_form=UpdatePasswordForm() form2=Form2() print update_password_form print form2 if update_password_form.validate_on_submit(): info=db.get_user_info(get_db(),g.user.id) old_password_ok=check_password( info['password'] , update_password_form.old_password.data ) new_passwords_match = update_password_form.new_password_1.data == update_password_form.new_password_2.data if old_password_ok and new_passwords_match: new_password_hash=encrypt(update_password_form.new_password_1.data) set_user_password(get_db(),g.user.id,new_password_hash) flash('Password updated') else: flash('Old password invalid or new passwords differ','error') return redirect( url_for('settings') ) elif form2.validate_on_submit(): flash('form2 %s'%form2.field.data) return redirect( url_for('settings') ) else: # no forms validate return render_template('settings.html',update_password_form=update_password_form,form2=form2)
def _issue_token_to_user(related_actions): try: login = request.json['login'] user_info = db.get_user_info(login) related_actions(user_info, login) return jsonify({ 'success': True, 'token': db.generate_new_token_for_user(login) }) except: return jsonify({ 'success': False, })
def main(): bot = telegram.Bot(token=BOT_TOKEN) open_db_connection() while True: now = int(time.time()) next_time = now data = get_temp_banned_members() for m in data: if m['banned_until'] > now: if m['banned_until'] > next_time: next_time = m['banned_until'] continue try: cm = bot.get_chat_member(chat_id=m['groupid'], user_id=m['userid']) if cm.status == "restricted" and cm.until_date is not None: set_user_ban(m['userid'], m['groupid'], cm.until_date.total_seconds()) continue if cm.status != "member": remove_user_ban(m['userid'], m['groupid']) continue infos = None if cm.user.username is not None and cm.user.username != "": infos = get_user_info(cm.user.username) if infos is None: bot.restrict_chat_member( chat_id=m['groupid'], user_id=m['userid'], can_send_messages=True, can_send_media_messages=False, can_send_other_messages=False, can_add_web_page_previews=False) logger.info("Restricted: %s (%s)" % (repr(cm.user.username), str(m['userid']))) remove_user_ban(m['userid'], m['groupid']) except (Unauthorized, BadRequest): remove_user_ban(m['userid'], m['groupid']) except: pass finally: time.sleep(0.1) renow = int(time.time()) if next_time == now or next_time > renow+10*60 or next_time <= renow: next_time = renow+10*60-3 next_time -= renow memoized().collect() logger.debug("Next run: " + str(next_time+3)) time.sleep(next_time+3)
def apply_restriction(userid): group = -1001055827794 print("Processing:", line, end="") cm = None try: cm = bot.get_chat_member(chat_id=group, user_id=userid) except TelegramError as err: print("Error get_chat_member():", str(err)) return if cm.status == "restricted" or cm.status == "kicked" or cm.status == "left" or cm.status == "administrator" or cm.status == "creator": #double check print("Not member: skipping") return if cm.status == "member" and (cm.can_send_messages is None or cm.can_send_messages == True): register_member(userid, group) else: print("Not member or can not send messages: skipping") return if cm is None or cm.user.username is None or cm.user.username == "": try: bot.restrict_chat_member(chat_id=group, user_id=userid, can_send_messages=True, can_send_media_messages=False, can_send_other_messages=False, can_add_web_page_previews=False) except TelegramError: print("Error restrict_chat_member():", str(err)) pass return infos = get_user_info(cm.user.username) if infos is None: try: bot.restrict_chat_member(chat_id=group, user_id=userid, can_send_messages=True, can_send_media_messages=False, can_send_other_messages=False, can_add_web_page_previews=False) except TelegramError as err: print("Error restrict_chat_member():", str(err)) pass finally: return print("User verified: skipping")
def get_user_list(passenger_id): origin, destination = db.get_user_info(passenger_id) response = "" if origin is not None and destination is not None: response += "Your current origin is {} and your destination is {}".format( origin, destination) elif origin is not None: response += "Your current origin is {}. However, you haven't defined a destination.".format( origin) elif destination is not None: response += "Your current destination is {}. However, you haven't defined an origin.".format( destination) else: response += "You haven't defined neither an origin nor a destination. Please specify one" data = {"text": response.encode("utf8"), "chat_id": passenger_id} requests.post(url, data)
def weather(message, uid): query = message.split(" ", 1) if len(query) < 2: result, ok = db.get_user_info(uid) if not ok: return {"answer": "", "status": 10} else: city = result[2] else: city = query[1] answer, ok, _ = api.weather(city) if ok: return {"answer": answer, "status": 200} else: return {"answer": "", "status": 11}
def town(message, uid): query = message.split(" ", 1) if len(query) < 2: return {"answer": "", "status": 20} _, ok = db.get_user_info(uid) if ok: ok2 = db.update_town(uid, query[1]) else: name, surname = vk_api_worker.get_user_names(uid) ok2 = db.add_user(uid, query[1], name, surname) if not ok2: return {"answer": "", "status": 100} if ok: return {"answer": answers[2], "status": 200} else: return {"answer": answers[1], "status": 200}
def show_stats(): first_name, last_name, age, state, nat_lang = db.get_user_info(1) mem_words_count = len(db.get_words(1, True)) unmem_words_count = len(db.get_words(1, False)) total_words_count = mem_words_count + unmem_words_count user_tests_scores = [score for score, in db.get_user_tests(1)] if user_tests_scores: average = sum(user_tests_scores) / len(user_tests_scores) max_score = max(user_tests_scores) min_score = min(user_tests_scores) else: average = min_score = max_score = 0 output = 'Name: %s %s\nAge: %d\nState: %s\nNative language: %s\n'\ 'Total words: %d\nMemorized words: %d\nUnmemorized words: %d\n'\ 'Tests passed: %d\nAverage score: %.2f\nMax score: %.2f\n'\ 'Min score: %.2f' % (first_name, last_name, age, state, nat_lang, total_words_count, mem_words_count, unmem_words_count, len(user_tests_scores), average, max_score, min_score) print output
def add_notification(message, uid): query = message.split(" ", 1) if len(query) < 2: return {"answer": "", "status": 41} _, ok = db.get_user_info(uid) if not ok: return {"answer": "", "status": 43} hour = query[1] try: hour = int(hour) except ValueError: return {"answer": "", "status": 41} if hour < 0 or hour > 23: return {"answer": "", "status": 42} db.update_timer(hour, uid) return {"answer": answers[40], "status": 200}
def account_login(user_id, password): user_info = db.get_user_info(user_id) if user_info: if user_info['password'] == password: return user_info return None
print(Fore.MAGENTA + "\n======= View Day ======="+ Style.RESET_ALL) day = read_positive_number("Enter the day: ",30) month = read_positive_number("Enter the month: ",12) year = read_positive_number("Enter the year: ",datetime.datetime.now().year) date = "%d-%02d-%02d"%(year,month,day) day_information = db.get_day(date) if day_information != None: print(day_information) else: print(Fore.WHITE + Back.RED + "\nThere is no stored data for the entered day " + date + "!" + Style.RESET_ALL + "\n" ) if __name__ == '__main__': reports_folder_path = os.path.join(os.path.expanduser("~"), "Desktop/", "next_level_reports") if not os.path.exists(reports_folder_path): os.makedirs(reports_folder_path) user = db.get_user_info() today = datetime.datetime.now() if user != None: welcome_text = ''' (\__/) (•ㅅ•) / づ %s ♥ WELCOME INTO YOUR NEXT LEVEL! -----------------------------''' % user.name print(Fore.BLUE + Style.BRIGHT + welcome_text + Style.RESET_ALL) print(Fore.CYAN + Style.BRIGHT + str(datetime.date.today()) + ", " + calendar.day_name[datetime.datetime.today().weekday()] + Style.RESET_ALL) else: user = set_up() day = db.get_day(datetime.datetime.today().strftime('%Y-%m-%d'))
def get_user_info(): if session.get('user_id'): return db.get_user_info(session['user_id'])
def get_user_info(host): port = 3306 data_json = db.get_user_info(host, port) data = json.loads(data_json) return jsonify(data)