添加rss生成
This commit is contained in:
parent
ca8a7d6d2f
commit
bf4fe4ce9f
58
gen_rss.py
Normal file → Executable file
58
gen_rss.py
Normal file → Executable file
@ -5,14 +5,34 @@
|
||||
import datetime
|
||||
import PyRSS2Gen
|
||||
import json
|
||||
import requests
|
||||
|
||||
file_path = "./rss.xml"
|
||||
|
||||
code_url = "https://git.zeekling.cn/"
|
||||
|
||||
resp_url = code_url + "api/v1/repos/search"
|
||||
|
||||
update_days = 5
|
||||
|
||||
params = {
|
||||
'sort': 'updated',
|
||||
'order': 'desc',
|
||||
'limit': 50
|
||||
}
|
||||
|
||||
|
||||
def gen_rss(items):
|
||||
items_rss = []
|
||||
for item in items:
|
||||
rss_item = PyRSS2Gen.RSSItem(
|
||||
title=item['full_name'],
|
||||
link=item['url'],
|
||||
description=item['des'],
|
||||
guid=PyRSS2Gen.Guid(item['url']),
|
||||
pubDate=item['update_time']
|
||||
)
|
||||
items_rss.append(rss_item)
|
||||
rss = PyRSS2Gen.RSS2(
|
||||
title="private code feed",
|
||||
link=code_url,
|
||||
@ -20,9 +40,45 @@ def gen_rss(items):
|
||||
lastBuildDate=datetime.datetime.now(),
|
||||
items=items_rss
|
||||
)
|
||||
rss.write_xml(file_path, 'w')
|
||||
rss.write_xml(open(file_path, 'w'))
|
||||
|
||||
|
||||
def get_items():
|
||||
items = []
|
||||
page = 1
|
||||
now_time = datetime.datetime.now()
|
||||
while True:
|
||||
params['page'] = page
|
||||
pages = requests.get(resp_url, params=params)
|
||||
tmp = json.loads(pages.text)
|
||||
data = tmp['data']
|
||||
if len(data) == 0:
|
||||
break
|
||||
use_able_count = 1
|
||||
for resp in data:
|
||||
update_time = datetime.datetime.strptime(resp['updated_at'],
|
||||
'%Y-%m-%dT%H:%M:%SZ')
|
||||
end_date = update_time + datetime.timedelta(days=update_days)
|
||||
if now_time >= end_date:
|
||||
continue
|
||||
use_able_count += 1
|
||||
entity = {
|
||||
'name': resp['name'],
|
||||
'url': resp['html_url'],
|
||||
'update_time': update_time,
|
||||
'full_name': resp['full_name'],
|
||||
'des': resp['description']
|
||||
}
|
||||
items.append(entity)
|
||||
page = page + 1
|
||||
if use_able_count == 1:
|
||||
break
|
||||
return items
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# main
|
||||
print('begin')
|
||||
items = get_items()
|
||||
print(items)
|
||||
gen_rss(items)
|
||||
|
3
rss.xml
Normal file
3
rss.xml
Normal file
@ -0,0 +1,3 @@
|
||||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<rss version="2.0"><channel><title>private code feed</title><link>https://git.zeekling.cn/</link><description>private code feed</description><lastBuildDate>Tue, 21 Apr 2020 10:41:32 GMT</lastBuildDate><generator>PyRSS2Gen-1.1.0</generator><docs>http://blogs.law.harvard.edu/tech/rss</docs><item><title>python/gitea-rss</title><link>https://git.zeekling.cn/python/gitea-rss</link><description>生成rss总的rss的代码。</description><guid isPermaLink="true">https://git.zeekling.cn/python/gitea-rss</guid><pubDate>Mon, 20 Apr 2020 13:15:50 GMT</pubDate></item><item><title>python/sitemap</title><link>https://git.zeekling.cn/python/sitemap</link><description>通过爬取网站,生成sitemap.xml
|
||||
</description><guid isPermaLink="true">https://git.zeekling.cn/python/sitemap</guid><pubDate>Mon, 20 Apr 2020 12:14:24 GMT</pubDate></item><item><title>mirror/ggfwzs_in_hack</title><link>https://git.zeekling.cn/mirror/ggfwzs_in_hack</link><description></description><guid isPermaLink="true">https://git.zeekling.cn/mirror/ggfwzs_in_hack</guid><pubDate>Mon, 20 Apr 2020 09:26:29 GMT</pubDate></item><item><title>zeekling/configs</title><link>https://git.zeekling.cn/zeekling/configs</link><description>个人配置相关信息</description><guid isPermaLink="true">https://git.zeekling.cn/zeekling/configs</guid><pubDate>Sun, 19 Apr 2020 10:58:39 GMT</pubDate></item><item><title>zeekling/index</title><link>https://git.zeekling.cn/zeekling/index</link><description>以前首页代码</description><guid isPermaLink="true">https://git.zeekling.cn/zeekling/index</guid><pubDate>Sat, 18 Apr 2020 04:43:11 GMT</pubDate></item><item><title>java/mybatis</title><link>https://git.zeekling.cn/java/mybatis</link><description>根据自己对mybatis的理解封装一个简易版的mybatis</description><guid isPermaLink="true">https://git.zeekling.cn/java/mybatis</guid><pubDate>Sat, 18 Apr 2020 04:42:51 GMT</pubDate></item><item><title>java/thinker</title><link>https://git.zeekling.cn/java/thinker</link><description>毕业设计时候用到的博客系统</description><guid isPermaLink="true">https://git.zeekling.cn/java/thinker</guid><pubDate>Sat, 18 Apr 2020 04:42:32 GMT</pubDate></item><item><title>python/photo</title><link>https://git.zeekling.cn/python/photo</link><description>简单相册,不过已经不会使用这个相册了,使用开源框架搭建了自己的图床,就不需要这个项目了。</description><guid isPermaLink="true">https://git.zeekling.cn/python/photo</guid><pubDate>Sat, 18 Apr 2020 04:41:34 GMT</pubDate></item><item><title>java/algorithm</title><link>https://git.zeekling.cn/java/algorithm</link><description>学习算法导论</description><guid isPermaLink="true">https://git.zeekling.cn/java/algorithm</guid><pubDate>Fri, 17 Apr 2020 16:19:30 GMT</pubDate></item></channel></rss>
|
Loading…
Reference in New Issue
Block a user