def generate_fake_data(): u = User.new(username='******', password='******') b = Board.new(title='demo') Board.new(title='demo2') with open('markdown_demo.md', encoding='utf8') as f: content = f.read() form = dict(title='markdown demo', content=content, board_id=b.id) Topic.new(form, u.id) form = dict(title='板块测试 demo2', content='**biu biu biu**', board_id='2') Topic.new(form, u.id) form = dict( topic_id=1, content='**hello world**', ) u = User.new( username='******', password='******', ) Reply.new(form, u.id) form = dict( topic_id=2, content='**hello world2**', ) Reply.new(form, u.id) form = dict(title='hey', content='happy', sender_id=1, receiver_id=2) Messages.new(**form)
def post(self): #GET THE CURRENT LOGGED IN USER user_key = self.logged_in_user_status.key #GET THE MESSAGE VALUES FROM THE FORM title = self.request.get('title') topic = self.request.get('topic') content = self.request.get('content') photo = self.request.POST['image'] if photo: saved_photo = self.save_image(photo, user_key) #ADD THE MESSAGE TO THE DATASTORE Messages.new_message(user_key=user_key, title=title, topic=topic, content=content, photo_key=saved_photo['blobstore_key'], photo_url=saved_photo['serving_url']) else: Messages.new_message(user_key=user_key, title=title, topic=topic, content=content, photo_key=None, photo_url='') #RETURN TO THE PERSONAL HOME PAGE self.redirect('/user_profile')
def send_mails(sender, receivers, content): print('send_mail', sender, receivers, content) for r in receivers: form = dict(title='你被 {} AT 了'.format(sender.username), content=content, sender_id=sender.id, receiver_id=r.id) Messages.new(**form)
def index(): u = current_user() sent_mail = Messages.all(sender_id=u.id) received_mail = Messages.all(receiver_id=u.id) t = render_template( 'mail/index.html', send=sent_mail, received=received_mail, ) return t
def output_json(): # CSV => List greetings = [] questions = [] thoughts = [] with open(CSV_PATH) as f: reader = csv.reader(f) for i, row in enumerate(reader): if i != 0: if len(row[1]) != 0: greetings.append(Message(i - 1, row[1])) if len(row[2]) != 0: questions.append(Message(i - 1, row[2])) if len(row[3]) != 0: thoughts.append(Message(i - 1, row[3])) # List => messages messages = Messages(greetings, questions, thoughts) with open(OUTPUT_PATH, 'w') as f: json.dump( {'data': messages}, f, default=default_method, ensure_ascii=False, indent=2, )
def view(id): mail = Messages.one(id=id) u = current_user() # if u.id == mail.receiver_id or u.id == mail.sender_id: if u.id in [mail.receiver_id, mail.sender_id]: return render_template('mail/detail.html', mail=mail) else: return redirect(url_for('.index'))
def get(self, key): #GET THE MESSAGE CLICKED ON BY THE USER message = Messages.get_by_id(int(key)) #GET THE AUTHOR OF THAT MESSAGE author = message.user.get() display_values = {'author': author} # DISPLAY THE FORM TO SEND OTHER USERS AN EMAIL self.render('email/send_email.html', **display_values)
def get(self, topic_id): #HANDLE THE REQUEST TO DISPLAY ALL MESSAGES WITH A CERTAIN TOPIC topic = Topics.get_by_id(int(topic_id)) #GET ALL MESSAGES WITH THE SAME TOPIC messages = Messages.ret_all_messages_by_topic(topic.topic_title) #GENERATE THE VALUES TO BE DISPLAYED display_values = {'messages': messages, 'topic': topic} self.render('message-page/topic-page.html', **display_values)
def get(self): #GET THE CURRENT USER ID user_id = self.logged_in_user_status.key.id() #GET ALL THE MESSAGES FOR THE USER messages = Messages.ret_all_messages_by_user(user_id) #GET ALL THE TOPICS FOR THE USER topics = Topics.ret_all_topics_by_user(user_id) #PARSING THE MESSAGES AND TOPICS TO THE TEMPLATE display_values = {'messages': messages, 'topics': topics} #RENDER THE PERSONAL HOME PAGE self.render('user_profile/account_home.html', **display_values)
def get(self, message_id): #DISPLAY THE MESSAGE PAGE WITH THE MESSAGE SELECTED BY THE USER message = Messages.get_by_id(int(message_id)) author = message.user.get() replies = Replies.ret_all_replies_by_message(int(message_id)) message_display_values = { 'message': message, 'author': author, 'message_id': message_id, 'replies': replies } self.render('message-page/message-page.html', **message_display_values)
def webhook(): if flask.request.headers.get('content-type') == 'application/json': request = flask.request.get_data().decode("utf-8") update = telebot.types.Update.de_json(request) if IGNORE_UNREAD_MESSAGES and not check_ready(update): return 'sleep' if update.message: Messages.add(update.message.chat.id, update.message.from_user.id, update.message.content_type, update.message.text) bot.process_new_messages([update.message]) if update.edited_message: bot.process_new_edited_messages([update.edited_message]) if update.inline_query: bot.process_new_inline_query([update.inline_query]) if update.chosen_inline_result: bot.process_new_chosen_inline_query( [update.chosen_inline_result]) if update.callback_query: bot.process_new_callback_query([update.callback_query]) return 'ok' else: flask.abort(403)
def message_create_post(): """ Create Job """ form = CreateMessageForm(request.form) username = session['username'] print "Post Message to Database::::" if request.method == 'POST': print "did it come inside?", form, form.validate(), request.form print "errors", form.errors if form.validate(): message = request.form['message'] obj = messageDecode.MessageDecode() messageTime = time.ctime() formatted_json_message = obj.decode(message, messageTime) #print "Formatted JSON:::" , formatted_json_message msg = Messages(username, formatted_json_message) #print "comes till here", msg.sender_username, msg.message try: db.session.add(msg) db.session.commit() flash('Message successfully added to the database.') return render_template('pages/create.message.html', user=user, form=form, jsonmsg=formatted_json_message) except sqlalchemy.exc.IntegrityError as e: db.session.rollback() # Log this properly and remove the print statement. print " The error is ", e flash('Job already Exists.\ Please check the details once') return redirect(url_for('.message_create_get')) else: flash("Please check the errors below") print "form is ", form, request.form return render_template('pages/create.message.html', user=user, form=form) return render_template('pages/create.message.html', user=user, form=form)
def post(self): #HANDLE THE REQUEST TO SUBMIT A REPLY TO A MESSAGE user_key = self.logged_in_user_status.key message_id = self.request.get('message_id') content = self.request.get('content') if message_id and content: #GET MESSAGE FROM MESSAGE ID message = Messages.get_by_id(int(message_id)) #ADD THE REPLY TO THE DATASTORE TABLE Replies.new_reply( user_key=user_key, message_key=message.key, content=content ) #RETURN BACK TO THE ORIGINAL MESSAGE PAGE self.redirect('/message/'+ message_id)
async def handlerNewMessage(event): print('app.py:events.NewMessage') event = event.message check = await participants.check(event.from_id) # print('app.py:check = ', check) if check: print('app.py:if(check[true])') db.messages.add( Messages(event.to_id.channel_id, event.from_id, event.message, event.id)) else: print('app.py:if(check[false])') print('Telegram :: Ошибка получение пользователя по Id\n') print("\n", "=-> " * 20, "\n", sep="")
def add(): form = request.form.to_dict() form['receiver_id'] = int(form['receiver_id']) u = current_user() form['sender_id'] = u.id r = User.one(id=form['receiver_id']) m = Message( subject=form['title'], body=form['content'], sender=admin_mail, recipients=[r.email] ) # mail.send(m) m = Messages.new(**form) return redirect(url_for('.index'))
def cmd_messages_count(message): try: typing(message) date = datetime.now(TIMEZONE) - timedelta(days=1) users = Messages.calculate(message.chat.id, date) text = ['Топ флудеров за последние 24 часа:'] if bot_id in users: users.pop(bot_id) for index, (user, karma) in enumerate(sorted(users.items(), key=lambda x: x[1], reverse=True), start=1): if index > 10: break text.append('{}) {}: {} сбщ.'.format( index, get_username_or_name(bot.get_chat(user)), karma)) bot.send_message(message.chat.id, '\n'.join(text), disable_notification=True) except: crash_message(message)
if args.list: for user in Users.load_all_users(cursor): print(""" User name: {} E-mail: {} """.format(user.username, user.email)) # send message from user1 to user2 if args.username and args.password and args.send and args.to: if user.validate_data(args.username, args.password, cursor): sender_id = user.get_id(args.username, cursor) receiver_id = user.get_id(args.to, cursor) if receiver_id == -1: print("Receiver doesn't exist !") else: Messages.send_message(sender_id, receiver_id, args.send, cursor) print("Message has been sent!") else: print("Invalid login data!") # history of messages if args.From and args.to and args.history: sender_id = user.get_id(args.From, cursor) receiver_id = user.get_id(args.to, cursor) if sender_id == -1 or receiver_id == -1: print("Invalid data!") else: Messages.load_all_messages( sender_id, args.From, receiver_id, args.to, cursor)
def makeMessage(self, data, **kwargs): return Messages(id=''.join(random.choices(string.ascii_letters + string.digits, k=16)), content=data['content'], time=pytz.utc.localize(datetime.utcnow()), courseid=data['courseID'])