def post(self): send = self.request.get("send") rec = self.request.get("rec") mess = self.request.get("mess") friend=User.query(User.uName==send).get() friend.flag=True friend.put() newMessage=Message(sender=send,receiver=rec,message=mess) newkey=newMessage.put() message=Message.query(ndb.OR(ndb.AND(Message.receiver==rec,Message.sender==send),ndb.AND(Message.receiver==send,Message.sender==rec))).order(Message.timestamp).fetch(40) response='Message Send Success!' # for m in message: # response+=m.str()+'\n' self.response.write(response)
def on_message_received(self, messages): parsed_messaged = [] for message in messages: if message.sender == message.chat_name: self.user_interaction_parser.handle(message) elif not self.whats_app_model.user_exists(message.sender): self.whats_app_model.add_user(message.sender) parsed_messaged.append(Message.Message(self.whats_app_model.get_user(message.sender), message.content, message.time, message.chat_name, None)) message_to_filter = [message for message in parsed_messaged if message.sender is not message.chat_name] messages_to_bot = [message for message in parsed_messaged if message.sender == message.chat_name] #print(message_to_filter) for message in messages_to_bot: self.user_interaction_parser.handle(message) filtered_message = self.message_filterer.filter(message_to_filter) for x in parsed_messaged: if x not in filtered_message and x.sender.phone_number+x.content not in self.seen_content: print(x.sender.phone_number, 'says', x.content) print(x.content,' is not important') self.seen_content.append(x.sender.phone_number+x.content) elif x.sender.phone_number + x.content not in self.seen_content: print(x.sender.phone_number, 'says', x.content) print(x.content,' is important') self.seen_content.append(x.sender.phone_number+x.content) if time.time() - self.last_print > 60: self.seen_content = [] self.last_print = time.time() self.whats_app_model.whats_app_storage.push_messages(filtered_message)
def post(self): send = self.request.get("send") rec = self.request.get("rec") mess = self.request.get("mess") friend = User.query(User.uName == send).get() friend.flag = True friend.put() newMessage = Message(sender=send, receiver=rec, message=mess) newkey = newMessage.put() message = Message.query( ndb.OR(ndb.AND(Message.receiver == rec, Message.sender == send), ndb.AND(Message.receiver == send, Message.sender == rec))).order( Message.timestamp).fetch(40) response = 'Message Send Success!' # for m in message: # response+=m.str()+'\n' self.response.write(response)
def format_messages(self, messages, group_name): formatted_messages = [] for i in range(0, len(messages)): j = 1 while j < len(messages[i]): formatted_messages.append( Message.Message(messages[i][0], messages[i][j], messages[i][j + 1], group_name, None)) j += 2 return formatted_messages
def post(self): talker=self.request.get("talker") user=self.request.get('user') friend=User.query(User.uName==talker).get() friend.flag=False friend.put() message=Message.query(ndb.OR(ndb.AND(Message.receiver==talker,Message.sender==user),ndb.AND(Message.receiver==user,Message.sender==talker))).order(Message.timestamp).fetch(40) response='' for m in message: response+=m.str()+'\n' print(talker) print(user) print(message) self.response.write(response)
def post(self): talker = self.request.get("talker") user = self.request.get('user') friend = User.query(User.uName == talker).get() friend.flag = False friend.put() message = Message.query( ndb.OR(ndb.AND(Message.receiver == talker, Message.sender == user), ndb.AND(Message.receiver == user, Message.sender == talker))).order( Message.timestamp).fetch(40) response = '' for m in message: response += m.str() + '\n' print(talker) print(user) print(message) self.response.write(response)
lucy = User(id='*****@*****.**', uName='Lucy', email='*****@*****.**', pwd='123', friend=['Tom', 'Jerry', 'Emma']) emma = User(id='*****@*****.**', uName='Emma', email='*****@*****.**', pwd='123', friend=['Tom', 'Lucy', 'Jerry']) tom.put() jerry.put() lucy.put() emma.put() #init Message m1 = Message(sender="Jerry", receiver="Tom", message="hello tom!") m2 = Message(sender="Tom", receiver="Jerry", message="Hi Jerry! what's up?") m3 = Message(sender="Tom", receiver="Emma", message="Hi Emma! what's up?") key_m1 = m1.put() # print('call put') key_m2 = m2.put() # print('call put') key_m3 = m3.put() # print('call put') #handeler class MainHandler(webapp2.RequestHandler): def get(self): template = JINJA_ENVIRONMENT.get_template('index.html') self.response.write(template.render())
from google.appengine.ext import ndb JINJA_ENVIRONMENT = jinja2.Environment( loader=jinja2.FileSystemLoader([os.path.dirname(__file__),os.path.dirname(__file__)+"/templates"])) #init User tom=User(id='*****@*****.**',uName='Tom',email='*****@*****.**',pwd='123',friend=['Jerry','Lucy','Emma']) jerry=User(id='*****@*****.**',uName='Jerry',email='*****@*****.**',pwd='123',friend=['Tom','Lucy','Emma']) lucy=User(id='*****@*****.**',uName='Lucy',email='*****@*****.**',pwd='123',friend=['Tom','Jerry','Emma']) emma=User(id='*****@*****.**',uName='Emma',email='*****@*****.**',pwd='123',friend=['Tom','Lucy','Jerry']) tom.put() jerry.put() lucy.put() emma.put() #init Message m1=Message(sender="Jerry",receiver="Tom",message="hello tom!") m2=Message(sender="Tom",receiver="Jerry",message="Hi Jerry! what's up?") m3=Message(sender="Tom",receiver="Emma",message="Hi Emma! what's up?") key_m1=m1.put() # print('call put') key_m2=m2.put() # print('call put') key_m3=m3.put() # print('call put') #handeler class MainHandler(webapp2.RequestHandler): def get(self): template = JINJA_ENVIRONMENT.get_template('index.html') self.response.write(template.render()) class SignUpHandler(webapp2.RequestHandler):