def update_context(user_id, field, text): user_data = user.get(user_id) if field in user_data: user.update(user_id, {field: text} ) else: conversations.update({'user_id': user_id}, {'$set': {'context.'+field: text}}) return True
def update_profile(): if 'file' in request.files: file = request.files['file'] user.avatar_save(session['id'], file) pitch = request.form['pitch'] region = request.form['region'] user.update(pitch, region, session['id']) return redirect('/user/profile/modify')
def account_profile(): global this_u_id user_info = user.read_one(this_u_id) print("My Account Information:") print(user_info) print("-" * 40) print(" Account Menu") print("-" * 40) logging.info("Print account_profile menu - Request user response\n") if admin == True: method = input(''' 1 = Update My Account Info 2 = Delete My Account 3 = Show All Accounts 4 = Main Menu 5 = Exit ''') else: method = input(''' 1 = Update My Account Info 2 = Delete My Account 4 = Main Menu 5 = Exit ''') if method == '1': logging.info("Response: 1 - Update Account Info\n") logging.info("Response 1 request user response\n") x = input("user name: ") z = getpass.getpass('Password:'******'2': logging.info("Response: 2 - Delete My Account\n") user.delete(this_u_id) this_u_id = 0 main_menu() elif method == '3': logging.info("Response: 3 - Show All Accounts\n") user.read_all() # print(all_users) account_profile() elif method == '5': logging.info("Response: 5 - Exit\n") exit() else: logging.info("Response: 4 - Main Menu\n") main_menu()
def analyze_watch(update, context): document = update.message.document f = None try: f = document.get_file(30) except telegram.TelegramError: update.message.reply_text( "An error occoured while downloading your file." ) return # Load the user and the data into a dataframe user = User.load(update.effective_user.id) json = f.download_as_bytearray().decode("utf-8") df = None try: df = ytd.load_watch_history(json, user.timezone) except Exception: update.message.reply_text( "An error occoured while parsing your file. 😵\n" "Maybe you uploaded a corrrupted file ?" ) return # Overall information about the searches info_message = ( "*Absolut numbers*\n" f"Videos watched since {df['time'].min().strftime('%b %d %Y')}: " f"*{len(df)}*\n" f"Average videos per day: " f"*{len(df)/((df['time'].max()-df['time'].min()).days):.2f}*" ) update.message.reply_text(info_message, parse_mode="Markdown") # Plot the most watched creators plt = ytd.creator_plot(df, 24) send_plot(user, context, plt) # Plot the watch timeline plt = ytd.watch_timeline_plot(df) send_plot(user, context, plt) # Plot the hours the users watches plt = ytd.watch_hour_plot(df) send_plot(user, context, plt) # Update the counter for the user user.analyzes += 1 user.update() update.message.reply_text("Done 😊", parse_mode="Markdown")
def logic(interaction, message): # We can also use the command number detected before user_id = message['user_id'] current_p = message['text'].split(' ')[0].lower() current_p_object = pending_conversations.get(current_p) if current_p_object is None: list_pending_conversations.logic(interaction, message) return True redirect_user_number = current_p_object['user_id'] user_found = user.get(redirect_user_number) if user_found is not None: conversation.update_context(user_id, 'redirect_user', user_found['id']) conversation.update_context(user_id, 'redirect_name', user_found['name']) conversation.update_context(user_id, 'redirect_phone', user_found['phone']) conversation.update_context(user_id, 'conversational_level', 'user') if user_found.get('owner') is None: user.update(user_found['id'], {'owner': user_id}) conversation.update_context(user_id, 'current_pending_conversation', current_p) pending_conversations.add_owner(current_p, user_id) pending_conversations.remove_new_messages(current_p) s_msg = "Haz selecionado al " + user_found['uuid'] + " " + user_found[ 'name'] chat_api.reply(s_msg, message) s_msg = "Con la conversacion pendiente " + current_p chat_api.reply(s_msg, message) else: already_selected_p = conversation.context( 'current_pending_conversation') if already_selected_p is None: list_pending_conversations.logic(interaction, message) else: already_p_object = pending_conversations.get(already_selected_p) already_user = user.get(already_p_object['user_id']) already_user_name = already_user.get('name') s_msg = "Sigues hablando con " + already_user_name chat_api.reply(s_msg, message) return True
def edit_user(id): username = request.cookies.get('username') if username == 'admin': if user.search_id(id): edit_id_url = '/user/edit/' + str(id) default_data = user.search_id(id) if request.methods == 'POST': user_data = request.form.to_dict() user.update(id, user_data) users_data = user.load() return render_template('user_list.html', users_info=users_data) return render_template('user_edit.html', action_url=edit_id_url, default_info=default_data) else: return "<h1> 当前用户无权限查看该页面</h1>"
def edit_user(id): username = request.cookies.get('username') if username == 'admin': if user.search_id(id): default_user = user.search_id(id) print default_user if request.method == 'POST': user_data = request.form.to_dict() user.update(id, user_data) users_data = user.load() return render_template('user_list.html', user_id=id, users_info=users_data, default_info=default_user) return render_template('user_edit.html', user_id=id) else: return "<h1> 当前用户无权限查看该页面</h1>"
def logic(interaction, message): user_id = message['user_id'] # We can also use the command number detected before redirect_user_number = message['text'].split(' ')[0].lower() users_uuid = user.find(uuid=redirect_user_number) try: user_found = users_uuid[0] except: user_found = None if user_found is not None: conversation.update_context(user_id, 'redirect_user', user_found['id']) conversation.update_context(user_id, 'redirect_name', user_found['name']) conversation.update_context(user_id, 'redirect_phone', user_found['phone']) conversation.update_context(user_id, 'conversational_level', 'user') if user_found.get('owner') is None: user.update(user_found['id'], {'owner': user_id}) current_p_results = pending_conversations.find( user_id=user_found['id'], closed=False) current_p = current_p_results[0].get( 'id') if len(current_p_results) > 0 else None if current_p is None: pending_conversations.create(user_found['id'], owners=[user_id]) current_p_results = pending_conversations.find( user_id=user_found['id'], closed=False) current_p = current_p_results[0].get( 'id') if len(current_p_results) > 0 else None conversation.update_context(user_id, 'current_pending_conversation', current_p) pending_conversations.add_owner(current_p, user_id) pending_conversations.remove_new_messages(current_p) s_msg = "Haz selecionado al " + user_found['uuid'] + " " + user_found[ 'name'] chat_api.reply(s_msg, message) s_msg = "Con la conversacion pendiente " + str(current_p) chat_api.reply(s_msg, message) else: list_users.logic() return True
def text_message(update, context): """Handle normal messages""" user = User.load(update.effective_user.id) if user.state == UserState.send_timezone: if update.message.text not in pytz.all_timezones: update.message.reply_text("Sorry, I don't know that timezone. 😰") return user.timezone = update.message.text user.state = UserState.idle user.update() update.message.reply_text("Great, set your new timezone. 😄") return # I don't know what else to do update.message.reply_text("Sorry, I don't know what you want. 😔")
def timezone_command(update, context): """Set the timezone for the user""" user = User.load(update.effective_user.id) user.state = UserState.send_timezone user.update() message = ( "Send me the timezone you live in.\n" "Unfortunatly, I am very strict about the format 😅.\n" "The format must be like `Europe/Vienna`.\n" "Here is the [Wikipedia Link]" "(https://en.wikipedia.org/wiki/List_of_tz_database_time_zones) " "to help you out." ) update.message.reply_text( message, parse_mode="Markdown", disable_web_page_preview=True )
def account_profile(): global this_u_id user_info = user.read_one(this_u_id) print("Account Information:") print(user_info) print("-" * 40) print(" Account Menu") print("-" * 40) if admin == True: method = input(''' 1 = Update My Account Info 2 = Delete My Account 3 = Show All Accounts 4 = Main Menu 5 = Delete Accounts 6 = Exit ''') else: method = input(''' 1 = Update My Account Info 2 = Delete My Account 4 = Main Menu 6 = Exit ''') if method == '1': x = input("user name: ") z = input("password: "******"email: ") user.update(this_u_id, x, z, y) account_profile() elif method == '2': user.delete(this_u_id) this_u_id = 0 main_menu() elif method == '3': all_users = user.read_all() print(all_users) account_profile() elif method == '5': x = input("Enter the ID of the account you want to delete") user.delete(x) account_profile() elif method == '6': exit() else: main_menu()
def settings(name): username = request.cookies.get('username') if username == name: users_data = user.load() url = '/settings/' + str(name) if request.method == 'POST': user_password = request.form.to_dict() if user_password['password'] == user_password['password1']: del user_password['password1'] for ur in users_data: # if ur['name'] == name: if ur[1] == name: # ur['password'] = user_passwords['password1'] # user.cover(users_data) user.update(ur[0], user_password) return '<h1> 密码更改成功<h2>' # FIXME user return render_template('settings.html', username=name, action_url=url) else: return flask.redirect(flask.url_for('/login'))
def test_update_user(self): # get existing User user = user_api.read_all()[0] # update username user['username'] = utils.generate_random_string(10) # do not update contact details del user['contact_details'] data, status = user_api.update(user.get('user_id'), user) self.assertEqual(status, 200)
def logic(interaction, message): user_id = message.get('user_id') user_context = conversation.context(user_id) current_user_id = user_context.get('redirect_user') if current_user_id is not None: current_user_name = user_context['redirect_name'] current_user_phone = user_context['redirect_phone'] notification.create(user_id, current_user_id, 0, settings = {'minutes': 5}) reply_text = 'Acabas de poner un timer de 5 min con en tu (conversación) con {current_user_name} ({current_user_phone})' chat_api.reply(reply_text, message) new_message_user = user_context.get('last_message_user') user_new_message = user.get(new_message_user) if new_message_user is None: chat_api.reply('Falle en encontrar el usuario para hablar', message) return True new_message_name = user_context['last_message_name'] new_message_phone = user_context['last_message_phone'] conversation.update_context(user_id, 'redirect_user', new_message_user) conversation.update_context(user_id, 'redirect_name', new_message_name) conversation.update_context(user_id, 'redirect_phone', new_message_phone) conversation.update_context(user_id, 'conversational_level', 'user') # Code shared with switch if user_found.get('owner') is None: user.update(redirect_user_id, { 'owner': user_id } ) chat_api.reply('La conversación con este usuario es:', message) user_messages = conversation.get_printable_conversation(redirect_user_id) chat_api.reply(user_messages, message) return True
def chat_event(self, nick, channel, message): """Chat event called by 'PRIVMSG channel'. Checks if the message is a command and sends it to the command processor at self.plugins Also checks whether the message was sent by one of the MC server bots, and responds appropriately. ~Also~ performs alias checking on the message !ALSO! parses any youtube links it sees into the .parseyoutube command. @returns Boolean -> message is a command """ def get_level(char): """Gets the privacy level of char returns int -> 0-2, 0 being most private """ if char == self.config.prchar: return 0 if char == self.config.char: return 1 if char == self.config.puchar: return 2 self.plugins.event(self, 'chat', (nick, channel, message)) # Get a user from the nick. This is important for # later on. user = self.get_user(nick) # Update the 'seen' field every message user.update_seen() ''' # Check through the aliases within the user's # file, and see if any match for alias in user.get_alias_list(): if ' '.join(message).startswith(alias): # Set message to alias result message = [] message = user.get_alias(alias).split(' ') print 'Alias recieved, "%s" to %s' % (alias, message) ''' # Create a new Input instance, seems easier # than a dictionary to work with. input = Input(nick, channel, message) # Set the user input.set_user(user) charset = (self.config.char, self.config.prchar, self.config.puchar) user.update() # Check if the message is actually a command. for c in charset: if message[0].startswith(c): # Throw new found command to the plugins.py module. input.set_command(message[0].split(c, 1)[1]) input.set_level(get_level(c)) self.plugins.event(self, 'command', (input)) return self.plugins.process_command(self, input) return False
def logic(interaction, message): user_id = message['user_id'] user_context = conversation.context(user_id) name = user_context.get('new_user_info_name') phone = user_context.get('new_user_info_phone') country = user_context.get('new_user_info_country') conversation.update_context(user_id, 'new_user_info_name', None) conversation.update_context(user_id, 'new_user_info_phone', None) conversation.update_context(user_id, 'new_user_info_country', None) id_create_user = user.phone_to_id(phone) users_by_name = user.find(name=name) user_same_name = users_by_name[0] if len(users_by_name) > 0 else None users_by_phone = user.find(phone=phone) user_same_phone = users_by_phone[0] if len(users_by_phone) > 0 else None no_change = False if user.get( id_create_user ) is None and user_same_phone is None and user_same_name is None: user_data = { 'name': name, 'phone': phone, 'country': country, 'owner': user_id, } user.create(id_create_user, user_data, 'outbound') message_start = { 'user_id': id_create_user, 'text': '***Inicio Conversacion Outbound' } pending_conversations.create(id_create_user, [user_id]) conversation.update_context(id_create_user, 'last_reply', datetime.now()) user_register = f"Haz registrado a un nuevo usuario. {name} ({phone})" chat_api.reply(user_register, message) elif user_same_phone is not None: if user_same_phone['name'] != name: user.update(user_same_phone['id'], {'name': name}) name_change = f"Haz cambiado el nombre del usuario con nombre de {name}" chat_api.reply(name_change, message) else: no_change = True elif user_same_name is not None: if user_same_name['phone'] != phone: user.update(user_same_name['id'], {'phone': phone}) phone_change = f"Haz cambiado el telefono del usuario con nombre de {name}" chat_api.reply(phone_change, message) else: no_change = True if no_change == True: chat_api.reply('El usuario no sufrio cambios', message) return True
while invalid: #take input until it is valid invalid = False user_choice = user.choice() if user_choice == 1: #if user select to borrow display.heading("which book are you borrowing?") display.matrix(book_list) user_select = user.choice() updated_data = book.borrow_book(user_select, user_data, book_list) user_data = updated_data[0] book_list = updated_data[1] log_msg = updated_data[2] print(log_msg) #updating files according to change user.update(user_name, user_data) log.update(user_name, log_msg) book.update(book_list) elif user_choice == 2: #if user select to return display.heading("which book are you returning?") display.user_data(user_data) if len(user_data) != 0: user_select = user.choice() updated_data = book.return_book(user_select, user_data, book_list) user_data = updated_data[0] book_list = updated_data[1] log_msg = updated_data[2] print(log_msg)