当前位置: 首页>>代码示例>>Python>>正文


Python Commons.markdown_escape方法代码示例

本文整理汇总了Python中inc.Commons.Commons.markdown_escape方法的典型用法代码示例。如果您正苦于以下问题:Python Commons.markdown_escape方法的具体用法?Python Commons.markdown_escape怎么用?Python Commons.markdown_escape使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在inc.Commons.Commons的用法示例。


在下文中一共展示了Commons.markdown_escape方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: format_item

# 需要导入模块: from inc.Commons import Commons [as 别名]
# 或者: from inc.Commons.Commons import markdown_escape [as 别名]
 def format_item(self, item):
     # Event destination
     channel = self.destination if isinstance(self.destination, Channel) else None
     user = self.destination if isinstance(self.destination, User) else None
     # Item data
     link = "https://reddit.com/r/{}/comments/{}/".format(self.subreddit, item["data"]["id"])
     title = item["data"]["title"]
     author = item["data"]["author"]
     author_link = "https://www.reddit.com/user/{}".format(author)
     url = item["data"]["url"]
     # Check if link is direct to a media file, if so, add photo to output message
     file_extension = url.split(".")[-1].lower()
     if file_extension in ["png", "jpg", "jpeg", "bmp", "gif", "mp4", "gifv"]:
         if file_extension == "gifv":
             url = url[:-4]+"mp4"
         # Make output message
         output = "Update on /r/{}/ subreddit. \"[{}]({})\" by [u/{}]({})\n[direct image]({})".format(
             Commons.markdown_escape(self.subreddit),
             Commons.markdown_escape(title),
             link,
             author,
             author_link,
             url)
         output_evt = EventMessageWithPhoto(self.server, channel, user, output, url, inbound=False)
         output_evt.formatting = EventMessage.Formatting.MARKDOWN
         return output_evt
     # Handle gfycat links as photos
     gfycat_regex = re.compile(r"(?:https?://)?(?:www\.)?gfycat\.com/([a-z]+)", re.IGNORECASE)
     gfycat_match = gfycat_regex.match(url)
     if gfycat_match is not None:
         direct_url = "https://giant.gfycat.com/{}.mp4".format(gfycat_match.group(1))
         # Make output message
         output = "Update on /r/{}/ subreddit. \"[{}]({})\" by [u/{}]({})\n[gfycat]({})".format(
             Commons.markdown_escape(self.subreddit),
             Commons.markdown_escape(title),
             link,
             author,
             author_link,
             url)
         output_evt = EventMessageWithPhoto(self.server, channel, user, output, direct_url, inbound=False)
         output_evt.formatting = EventMessage.Formatting.MARKDOWN
         return output_evt
     # Handle reddit video links
     vreddit_regex = re.compile(r"https?://v.redd.it/[a-z0-9]+")
     vreddit_match = vreddit_regex.match(url)
     if vreddit_match is not None:
         if item["data"]["secure_media"] is None:
             direct_url = item["data"]["crosspost_parent_list"][0]["secure_media"]["reddit_video"]["fallback_url"]
         else:
             direct_url = item["data"]["secure_media"]["reddit_video"]["fallback_url"]
         # Make output message
         output = "Update on /r/{}/ subreddit. \"[{}]({})\" by [u/{}]({})\n[vreddit]({})".format(
             Commons.markdown_escape(self.subreddit),
             Commons.markdown_escape(title),
             link,
             author,
             author_link,
             direct_url)
         output_evt = EventMessageWithPhoto(self.server, channel, user, output, direct_url, inbound=False)
         output_evt.formatting = EventMessage.Formatting.MARKDOWN
         return output_evt
     # Make output message if the link isn't direct to a media file
     if item["data"]["selftext"] != "":
         output = "Update on /r/{}/ subreddit. \"[{}]({})\" by [u/{}]({})".format(
             Commons.markdown_escape(self.subreddit),
             Commons.markdown_escape(title),
             link,
             author,
             author_link)
     else:
         output = "Update on /r/{}/ subreddit. \"[{}]({})\" by [u/{}]({})\n{}".format(
             Commons.markdown_escape(self.subreddit),
             Commons.markdown_escape(title),
             link,
             author,
             author_link,
             url,
             link)
     output_evt = EventMessage(self.server, channel, user, output, inbound=False)
     output_evt.formatting = EventMessage.Formatting.MARKDOWN
     return output_evt
开发者ID:joshcoales,项目名称:Hallo,代码行数:83,代码来源:Subscriptions.py


注:本文中的inc.Commons.Commons.markdown_escape方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。