def update_notice(novel): favs = UserFavorite.select().where((UserFavorite.novel_id == novel.id) & (UserFavorite.notice_enable > 0)) for fav in favs: user = UserProfile.get_by_id(fav.user_id) if user.email: subject = "小说更新通知" utils.send_update_online_email(subject, user.email, novel.novel_name) elif user.mobile: utils.send_update_sms(user.mobile, novel.novel_name) else: try: message = "您收藏的小说({0})已经有更新了, 请前往阅读.".format(novel.novel_name) UserMessage.create(message=message, user_id=user.id) logger.info("发送小说[{0}]更新消息给用户[{1}]成功".format( novel.novel_name, user.username)) except Exception as e: logger.error("发送小说[{0}]更新消息给用户[{1}]失败, 原因:{2}".format( novel.novel_name, user.username, e))