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')
(完)
爬坑小程序
button样式,图片排列有空隙,时间转时间戳,隐藏滚动条
小程序云函数运用
小程序获取手机号,openid
老妈,母亲节快乐
向我们的衣食父母鞠躬
谈谈我的blog
kedong.me
长线 or 短线?
小孩子才做选择
Docker基本操作
一些基本操作,指令
等待你的评论