本文整理汇总了Python中models.Message.query_time_from_chat方法的典型用法代码示例。如果您正苦于以下问题:Python Message.query_time_from_chat方法的具体用法?Python Message.query_time_from_chat怎么用?Python Message.query_time_from_chat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Message
的用法示例。
在下文中一共展示了Message.query_time_from_chat方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import query_time_from_chat [as 别名]
def post(self):
data = json.loads(self.request.body)
user = users.get_current_user()
client_id = data['id']
chat = ndb.Key(urlsafe=client_id[:-8]).get()
if user:
Activity(
user = user,
chat = chat.key).put()
for client in chat.clients:
channel.send_message(
client,
json.dumps(
{"clients":len(chat.clients)+1,
"name": chat.name,
"cursor": False,
"message": []
}
)
)
last_message_when = Message.query_time_from_chat(chat.key)
if last_message_when < (
datetime.datetime.now()-datetime.timedelta(hours=4)):
logging.info('Reset clients in chat {}'.format(chat.key.urlsafe()))
chat.reset_clients()
chat.add_client(client_id)
示例2: get
# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import query_time_from_chat [as 别名]
def get(self):
if self.request.get('user'):
user = users.get_current_user()
if user:
chats = ChatManager.query_user(user,10)
activity = Activity.query_user(user,10)
else:
chats = ChatManager.query_public(10)
activity = []
chat_list = list()
for c in chats:
chat_list.append(
{"name": c.name,
"date": c.date.strftime('%Y-%m-%dT%H:%M:%SZ'),
"owner": c.owner.nickname(),
"key": c.key.urlsafe(),
"persistent": c.options['persistent'],
"save": c.save,
"conversations": c.options['conversations'],
"num_clients": c.num_clients(),
"private": c.private}
)
activity_list = list()
for a in activity:
thischat = a.chat.get()
activity_list.append(
{"name": thischat.name,
"date": a.date.strftime('%Y-%m-%dT%H:%M:%SZ'),
"key": thischat.key.urlsafe(),
"last": Message.query_time_from_chat(a.chat).strftime('%Y-%m-%dT%H:%M:%SZ'),
"creator": thischat.owner.nickname()}
)
self.response.out.headers['Content-Type'] = 'application/json'
self.response.out.write(json.dumps({'chats': chat_list,
'activity': activity_list}))