def process_message(reddit, message): entry = db.get_entry(message.subject[4:].lower()) if entry == None: return submission = reddit.submission(entry.id) if check_post_deleted(submission): remove_entry(entry.id) return code = entry.code body = message.body next_code = parse_message(code, body) if next_code == None: status = message.reply( f'{INVALID_RESPONSE}\n\n{get_response(code).comment}') if status == None: db.remove_entry(entry.id) else: response = get_response(next_code) assert (response != None) status = message.reply(response.comment) if status == None: db.remove_entry(entry.id) return if get_response(code).sticky: submission.reply( f'OP\'s response to the question "{get_response(code).comment}": \n>{body}' ).mod.distinguish() if response.end: submission.mod.approve() submission.reply(f'{APPROVAL_MESSAGE}').mod.distinguish() db.remove_entry(entry.id) else: db.update_code(entry.id, next_code)
def view_entry(diary_id=None): ''' Function names are following the Google Python style guide ''' ## NOW we are using diary_id. Should we call it entry_id instead? ## Notice, since this time it is a single entry we are type casting to dict entry = get_entry(diary_id) return render_template('view_entry.html', entry=dict(entry))
def get(self, index): entry = db.get_entry(index) if not entry: raise tornado.web.HTTPError(404) # XXX maybe should do comments paging with ajax comment_start = self.get_argument("comment_start", None) comments, extra_comment = db.get_comments(index, comment_start, config.COMMENTS_PER_PAGE) self.render("entry.html", entry=entry, comments=comments, extra_comment=extra_comment)
def view_entry(diary_id=None): ''' Function names are following the Google Python style guide ''' ## NOW we are using diary_id. Should we call it entry_id instead? ## Notice, since this time it is a single entry we are type casting to dict ## ****Also make a note of that, we are not checking the privacy settings when we ## retrive single entry based on the ID. as we assume that no entry which is ## private and created by another user than the current user, will not be shown ## in the index page itself. So, it is out of question for somebody who does not own ## an entry to navigate to this view page to view that entry if that entry is private.***** entry = get_entry(diary_id) return render_template('view_entry.html', entry=dict(entry))
def get_contact(contact): """ """ entry = [] try: if contact.split()[1]: entry.append(contact.split()[0]) entry.append(contact.split()[1]) except: entry.append('') entry.append(contact.split()[0]) for row in db.get_entry(db.get_id(entry)): return row
def webhook(): if request.method == 'GET': token = request.args.get('hub.verify_token') challenge = request.args.get('hub.challenge') if token == 'secret': return str(challenge) return '400' else: data = json.loads(request.data) print(data) messaging_events = data['entry'][0]['messaging'] bot = Bot(PAGE_ACCESS_TOKEN) for message in messaging_events: user_id = message['sender']['id'] text_input = message['message'].get('text') response_text = 'I am still learning' if text_input in GREETINGS: response_text = 'Hello. Welcome to my first bot!' elif check_width_height_syntax(text_input) is True: image_url = get_entry(user_id) if image_url is None: response_text = 'Please upload image first' else: bot.send_text_message(user_id, '..Processing your image..') resize_image(image_url, text_input) bot.send_image(user_id, 'output.png') bot.send_text_message(user_id, 'You are all set') delete_entry(user_id) return '200' else: attachments = message['message'].get('attachments') if attachments: attachment = attachments[0] attachment_type = attachment.get('type') if attachment_type == 'image': create_entry( user_id, (attachment.get('payload', {}).get('url'))) response_text = 'Thanks. I will help you resize. Tell me the size in width x height(200x100)' print('Message from user ID {} - {}'.format(user_id, text_input)) bot.send_text_message(user_id, response_text) return '200'
def get_contact(contact): """Returns a contact. Keyword arguments: contact -- First and Last name of a contact entry """ entry = [] try: if contact.split()[1]: entry.append(contact.split()[0]) entry.append(contact.split()[1]) except: entry.append('') entry.append(contact.split()[0]) for row in db.get_entry(db.get_id(entry)): return row
def get_contact(contact): """Returns a contact. Keyword arguments: contact -- First and Last name of a contact entry """ entry = [] try: if contact.split()[1]: entry.append(contact.split()[0]) entry.append(contact.split()[1]) except: entry.append("") entry.append(contact.split()[0]) for row in db.get_entry(db.get_id(entry)): return row
def decode_text(zlibText): return db.get_entry(zlibText) return zlibText return zlibText.decode('zlib_codec').decode('ascii')
def get(self): index = self.get_argument("index", None) entry = db.get_entry(index) if index else None tags = db.get_tags() tags = tags and " ".join([t.name for t in tags]) or "" self.render("compose.html", entry=entry, tags=tags)
clear() # Print User Menu print(user_menu()) #Input Menu Option op = input('Ingrese una opcion: ') clear() if (valid_menu_input(op)): if (op == '1'): print("\n\tCrear un nuevo registro") user = new_entry(user, user_credentials) elif (op == '2'): print("\n\tMostrar un registro") get_entry(user, user_credentials) elif (op == '3'): print("\n\tEliminar un registro") user = delete_entry(user, user_credentials) elif (op == '4'): wants_to_continue_user_menu = False else: error_msg( 'La opcion ingresada no es valida.') else: error_msg('La opcion ingresada no es valida.') else: error_msg("Las credenciales son invalidas.") elif (op == '2'): # Crear Usuario