-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
42 lines (30 loc) · 1.06 KB
/
Copy pathmain.py
File metadata and controls
42 lines (30 loc) · 1.06 KB
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
import xml.etree.ElementTree as ET
import configparser
config = configparser.ConfigParser()
config.read('config.ini')
input_file = config['config']['input_file']
output_file = config['config']['output_file']
def parse_opml_file(opml_file):
try:
tree = ET.parse(opml_file)
except FileNotFoundError:
print(f"Arquivo OPML não encontrado!")
exit()
root = tree.getroot()
html_content = ""
for outline in root.findall('.//outline'):
text = outline.get('text')
html_url = outline.get('htmlUrl')
if text and html_url:
link = f'<a href="{html_url}">{text}</a><br>\n'
html_content += link
return html_content
def save_html_file(html_content, output_file):
with open(output_file, 'w', encoding='utf-8') as f:
f.write('<html><body>')
f.write(html_content)
f.write('</main>')
f.write('</body></html>')
html_content = parse_opml_file(input_file)
save_html_file(html_content, output_file)
print(f"Arquivo HTML gerado: {output_file}")