def hello(message, session): blogapi = BlogApi() result = blogapi.search_articles(message.content) if result: articles = list(map(lambda x: x.object, result)) reply = convert_to_articlereply(articles, message) return reply else: return "没有找到相关文章"
robot = WeRoBot(token='lylinux', enable_session=True) memstorage = MemcacheStorage() # TODO 在容器中会报错 不存在文件werobot_session 但是文件在容器中是存在的 可能是操作系统的原因 # if memstorage.is_available: # robot.config['SESSION_STORAGE'] = memstorage # else: # from werobot.session.filestorage import FileStorage # import os # from django.conf import settings # # if os.path.exists(os.path.join(settings.BASE_DIR, 'werobot_session')): # print("=====================================") # print(os.path.join(settings.BASE_DIR, 'werobot_session')) # os.remove(os.path.join(settings.BASE_DIR, 'werobot_session')) # robot.config['SESSION_STORAGE'] = FileStorage(filename='werobot_session') blogapi = BlogApi() tuling = TuLing() def convert_to_articlereply(articles, message): reply = ArticlesReply(message=message) from blog.templatetags.blog_tags import custom_markdown, truncatechars_content from web.utils import CommonMarkdown from django.utils.safestring import mark_safe for post in articles: imgs = re.findall(r'(?:http\:|https\:)?\/\/.*\.(?:png|jpg)', post.body) imgurl = '' if imgs: imgurl = imgs[0] article = Article(title=post.title, description=truncatechars_content(post.body),