-
Notifications
You must be signed in to change notification settings - Fork 1
/
Gmerss.py
125 lines (111 loc) · 3.81 KB
/
Gmerss.py
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# -*- coding: utf-8 -*-
import os
import json
import time
import feedparser
######################################################################################
displayDay=7 # 抓取多久前的内容
displayMax=2 # 每个RSS最多抓取数
weeklyKeyWord="" # 周刊过滤关键字
rssBase={
"独立开发变现":{
"url":"https://www.ezindie.com/feed/rss.xml",
"type":"weekly",
"timeFormat":"%a, %d %b %Y %H:%M:%S GMT",
"nameColor":"#a4244b"
},
"夜枫":{
"url":"https://yefengs.com/feed",
"type":"post",
"timeFormat":"%a, %d %b %Y %H:%M:%S +0000",
"nameColor":"#b8d101"
},
"kn007":{
"url":"https://kn007.net/feed/",
"type":"post",
"timeFormat":"%a, %d %b %Y %H:%M:%S +0000",
"nameColor":"#e76976"
},
"二丫讲梵":{
"url":"https://wiki.eryajf.net/learning-weekly.xml",
"type":"weekly",
"timeFormat":"%a, %d %b %Y %H:%M:%S +0800",
"nameColor":"#93bd76"
},
"豌豆花下猫":{
"url":"https://pythoncat.top/rss.xml",
"type":"weekly",
"timeFormat":"%a, %d %b %Y %H:%M:%S GMT",
"nameColor":"#bc4c00"
},
"1Link":{
"url":"https://1link.fun/index.xml",
"type":"weekly",
"timeFormat":"%a, %d %b %Y %H:%M:%S +0000",
"nameColor":"#7479dc"
},
"阮一峰":{
"url":"http://www.ruanyifeng.com/blog/atom.xml",
"type":"weekly",
"timeFormat":"%Y-%m-%dT%H:%M:%SZ",
"nameColor":"#1f883d"
},
"老胡的周刊":{
"url":"https://weekly.howie6879.com/rss/rss.xml",
"type":"weekly",
"timeFormat":"%a, %d %b %Y %H:%M:%S +0806",
"nameColor":"#A333D0"
},
"Meekdai":{
"url":"https://blog.meekdai.com/rss.xml",
"type":"post",
"timeFormat":"%a, %d %b %Y %H:%M:%S +0000",
"nameColor":"#df7150"
}
}
######################################################################################
rssAll=[]
info=json.loads('{}')
info["published"]=int(time.time())
info["rssBase"]=rssBase
rssAll.append(info)
displayTime=info["published"]-displayDay*86400
print("====== Now timestamp = %d ======"%info["published"])
print("====== Start reptile Last %d days ======"%displayDay)
for rss in rssBase:
print("====== Reptile %s ======"%rss)
rssDate = feedparser.parse(rssBase[rss]["url"])
i=0
for entry in rssDate['entries']:
if i>=displayMax:
break
if 'published' in entry:
published=int(time.mktime(time.strptime(entry['published'], rssBase[rss]["timeFormat"])))
if entry['published'][-5]=="+":
published=published-(int(entry['published'][-5:])*36)
if rssBase[rss]["type"]=="weekly" and (weeklyKeyWord not in entry['title']):
continue
if published>info["published"]:
continue
if published>displayTime:
onePost=json.loads('{}')
onePost["name"]=rss
onePost["title"]=entry['title']
onePost["link"]=entry['link']
onePost["published"]=published
rssAll.append(onePost)
print("====== Reptile %s ======"%(onePost["title"]))
i=i+1
else:
published = None
print("Warning: 'published' key not found in entry")
print("====== Start sorted %d list ======"%(len(rssAll)-1))
rssAll=sorted(rssAll,key=lambda e:e.__getitem__("published"),reverse=True)
if not os.path.exists('docs/'):
os.mkdir('docs/')
print("ERROR Please add docs/index.html")
listFile=open("docs/rssAll.json","w")
listFile.write(json.dumps(rssAll))
listFile.close()
print("====== End reptile ======")
######################################################################################