-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathopml_generator.py
More file actions
31 lines (21 loc) · 810 Bytes
/
opml_generator.py
File metadata and controls
31 lines (21 loc) · 810 Bytes
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
from xml.sax.saxutils import quoteattr
with open('mirror-original.csv', 'r') as f:
file_content = f.read()
lines = file_content.split('\n')
HEAD = '<?xml version="1.0" encoding="UTF-8"?><opml version="1.0"><head><title>优质 Mirror 信息源列表</title></head><body>'
END = '</body></opml>'
ITEM = '<outline text={title} title={title} type="rss" xmlUrl={rss_link} htmlUrl={link}/>'
content = HEAD
for line in lines[1:]:
line = line.strip()
if not line:
continue
parts = line.split(',')
if len(parts) != 4:
continue
parts = [part.strip() for part in parts]
if parts[2]:
content += ITEM.format(title=quoteattr(parts[0]), link=quoteattr(parts[1]), rss_link=quoteattr(parts[2]))
content += END
with open('feed.opml', 'w') as f:
f.write(content)