Python生成一个最简单的rss.xml

image.png

一个最简单的RSS从了解查询到实际应用竟然用了一天,我一定是在摸鱼... 网上杂乱的信息太多,个人记录下。 下面的set1是一个mongo集合。

          
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
from feedgen.feed import FeedGenerator def update_rss(set1): # 创建FeedGenerator对象 fg = FeedGenerator() fg.id('http://kedong.me/rss') fg.title('KirkDong RSS Feed') fg.author({'name': 'KirkDong', 'email': 'xxxxx@gmail.com'}) fg.link(href='https://kedong.me', rel='alternate') fg.language('zh-cn') # 添加条目 cursor = set1.find({}, {"_id": 0}).sort("article_id", -1).limit(20) for i in cursor: fe = fg.add_entry() fe.id(str(i["article_id"]) ) fe.title(i["title"]) #i["article_id"]加到https://kedong.me/ fe.link(href="https://kedong.me/article_id/{0}".format(i["article_id"])) fe.description(i["description"]) # i.date是string 2021/12/31 16:25格式转换中国时间 fe.pubDate(datetime.datetime.strptime(i["date"]+':00', "%Y/%m/%d %H:%M:%S").strftime("%a, %d %b %Y %H:%M:%S +0800")) # 将Feed转换为字符串 # rss_xml = fg.atom_str(pretty=True) # 将XML输出到文件 fg.atom_file('rss.xml')
(完)
春节那点事
对象那点事ヽ(ー_ー)ノ
Vue中的keep-alive应用
结合activated,deactivated使用
Chrome浏览器google翻译无法使用
google翻译无法使用解决方案
浅拷贝深拷贝
前端基本技能,面试必备
随便谈谈最近股市
全网都是AI了吧
北高峰爬山
天下第一财神庙,抽了个签
等待你的评论