本文整理汇总了Python中models.Subscription.remove_subscription方法的典型用法代码示例。如果您正苦于以下问题:Python Subscription.remove_subscription方法的具体用法?Python Subscription.remove_subscription怎么用?Python Subscription.remove_subscription使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Subscription
的用法示例。
在下文中一共展示了Subscription.remove_subscription方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from models import Subscription [as 别名]
# 或者: from models.Subscription import remove_subscription [as 别名]
def post(self):
USAGE = u"""使用方法:
* 回复 "1 <关键字>", 接收租房推送;
* 回复 "2", 查询当前订阅的关键字;
* 回复 "3 <编号>", 取消查询结果中编号对应的关键字;
* 回复任意信息,续定推送(微信有规定48小时内没交流就不许我发信息给你了。。。)
"""
signature = self.request.get('msg_signature')
timestamp = self.request.get('timestamp')
nonce = self.request.get('nonce')
try:
wechat.parse_data(self.request.body, signature, timestamp, nonce)
if isinstance(wechat.message, messages.TextMessage):
content = wechat.message.content.strip()
user = wechat.message.source
resp = ''
logging.debug('got message (%s) from %s' % (content, user))
try:
if re.match(u'1', content):
keyword = content[1:].strip()
ret = Subscription.add_subscription(user, keyword)
logging.debug(ret)
if ret:
resp = u'订阅成功!'
else:
raise Exception('subscription failed')
elif re.match(u'3', content):
try:
idx = int(content[1:].strip())
ret = Subscription.get_user_subscriptions(user)
if len(ret):
if idx < len(ret):
keyword = ret[idx]['keyword']
ret = Subscription.remove_subscription(user, keyword)
if ret:
resp = u'订阅取消成功(%s)!' % keyword
else:
raise Exception('subscription removal failed')
else:
resp = u'没有找到编号为%d的订阅诶。。您一共有%d个订阅。' % (idx, len(ret))
else:
resp = u'您当前没有订阅。'
except Exception as e:
raise
elif re.match(u'2', content):
ret = Subscription.get_user_subscriptions(user)
if len(ret):
resp = u'您的当前订阅:\n%s' % '\n'.join(
['%d: %s' % (idx, r['keyword']) for idx, r in enumerate(ret)])
else:
resp = u'您当前没有订阅。'
else:
# TODO: respond something meaningful
resp = USAGE
except Exception as e:
logging.debug(repr(e))
resp = USAGE
logging.debug('replying with (%s)' % resp)
self.response.write(wechat.response_text(resp))
except Exception as e:
logging.warning(repr(e))
logging.warning(e.message)
import traceback
traceback.print_exc()
self.response.write('')