MCPcopy
hub / github.com/tangqiaoboy/iOSBlogCN / handler

Function handler

Export.py:12–46  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

10workmd = work + os.path.sep + 'README.md'
11
12def handler():
13 isblock = True
14 handlerData = []
15 lineNo = 0
16 try:
17 with open(workmd,'rb') as linefs:
18 lineCout = len(linefs.readlines())
19 linefs.close()
20 with open(workmd,'rb') as fs:
21 while isblock:
22 lineNo += 1
23 val = fs.readline().decode()
24 if lineNo == lineCout:
25 isblock = False
26 if not val[0] == '[':
27 continue
28 title = re.findall(r'\[(.+?)\]',val)[0]
29 xmlUrls = re.findall(r'<(.+?)>',val)
30 if not xmlUrls:
31 continue
32 xmlUrl = xmlUrls[0]
33 htmlUrl = re.findall(r'\((.+?)\)',val)[0]
34 handlerData.append('<outline text="{0}" title="{0}" type="rss" xmlUrl="{1}" htmlUrl="{2}"/>'.format(title,xmlUrl,htmlUrl))
35 fs.close()
36 except:
37 print('错误处理','读取文件失败')
38 return
39 export_xml = '<?xml version="1.0" encoding="UTF-8"?><opml version="1.0"><head><title>导出订阅</title></head><body><outline text="ios" title="ios" >\n'
40 export_xml += '\r\n'.join(handlerData)
41 export_xml += '</outline></body></opml>\r\n'
42 with open(resxml,'wb') as fs:
43 fs.write(export_xml.encode())
44 fs.close()
45 print('res.xml文件处理完成')
46 pass
47if os.path.isfile(workmd):
48 handler()
49

Callers 1

Export.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected