Commit 36ad081c authored by Etienne Nadji's avatar Etienne Nadji

toOpml.py

	modifié :         reco.opml
	modifié :         reco.xml
	modifié :         toOpml.py
parent 849d17f0
This diff is collapsed.
......@@ -19,7 +19,7 @@ Si tu lis ces lignes:
<emissions>
<update>05/01/2015</update>
<update>06/01/2015</update>
<category name="Collectifs" anchor="collectifs">
<emission>
......
......@@ -19,25 +19,37 @@ def get_datas(xml_file):
e["title"] = elem.text
if elem.tag == "links":
for link in elem:
if link.tag == "url":
for v in link.attrib.values():
if v == "rss":
e["urls"].append(link.text)
if v == "yt":
if link.text.startswith('user/'):
e["urls"].append(
"https://www.youtube.com/feeds/videos.xml?user={0}".format(
link.text.split('/')[-1]
)
)
if link.text.startswith('channel/'):
e["urls"].append(
"https://www.youtube.com/feeds/videos.xml?channel_id={0}".format(
link.text.split('/')[-1]
)
)
text = link.text
if "type" in link.attrib.keys():
url_type = link.attrib["type"]
else:
url_type = False
if "subType" in link.attrib.keys():
url_subtype = link.attrib["subType"]
else:
url_subtype = False
if url_type:
if url_type == "rss":
e["urls"].append(text)
if url_type == "web":
if "rssUrl" in link.attrib.keys():
e["urls"].append("{0}{1}".format(text,link.attrib["rssUrl"]))
if url_type == "yt":
if url_subtype in ["user","channel"]:
ref = {
"user":"https://www.youtube.com/feeds/videos.xml?user=",
"channel":"https://www.youtube.com/feeds/videos.xml?channel_id="
}
e["urls"].append("{0}{1}".format(ref[url_subtype],text))
if len(e["urls"]) > 0:
emissions.append(e)
......@@ -80,13 +92,13 @@ def write_opml(datas):
ret = ''
for url in emission["urls"]:
url = 'xmlUrl="{0}"'.format(url)
ret += '\t<outline text="" {0}type="rss" {1}/>\n'.format(title,url)
ret += ' <outline text="" {0}type="rss" {1}/>\n'.format(title,url)
return ret
else:
url = 'xmlUrl="{0}"'.format(emission["urls"][0])
return '\t<outline text="" {0}type="rss" {1}/>\n'.format(title,url)
return ' <outline text="" {0}type="rss" {1}/>\n'.format(title,url)
if datas:
with open("reco.opml","w") as opmlf:
......@@ -94,10 +106,10 @@ def write_opml(datas):
opmlf.write('<opml version="2.0">\n')
opmlf.write('<head>\n')
opmlf.write('\t<title>Recommandations d\'émissions</title>\n')
opmlf.write(' <title>Recommandations d\'émissions</title>\n')
if datas["update"] is not None:
opmlf.write('\t<dateCreated>{0}</dateCreated>\n'.format(datas["update"]))
opmlf.write(' <dateCreated>{0}</dateCreated>\n'.format(datas["update"]))
opmlf.write('</head>\n')
opmlf.write('<body>\n')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment