Skip to content

Commit

Permalink
foo
Browse files Browse the repository at this point in the history
  • Loading branch information
jantman committed Nov 10, 2015
1 parent 1b659ab commit bd2af22
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions puppetconf_to_youtube.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env python
"""
Script to generate a YouTube playlist from a puppet videos page
"""

import sys
import requests

try:
from lxml import etree, html
except ImportError:
try:
# normal cElementTree install
import cElementTree as etree
except ImportError:
try:
# normal ElementTree install
import elementtree.ElementTree as etree
except ImportError:
raise SystemExit("Failed to import ElementTree from any known place")


VIDEO_PAGE = 'https://puppetlabs.com/puppetconf-2015-videos-and-presentations'

def main():
r = requests.get(VIDEO_PAGE)
tree = html.fromstring(r.text)
links = []
for item in tree.iterlinks():
element, attrib, link, pos = item
if not link.startswith('https://puppetlabs.com/presentations/'):
continue
links.append(link)
print("# Found %d links" % len(links))
for link in links:
do_link(link)

def do_link(link):
r = requests.get(link)
tree = html.fromstring(r.text)
for item in tree.xpath('//iframe'):
if 'src' in item.attrib and 'youtube.com' in item.attrib['src']:
print(item.attrib['src'])

if __name__ == "__main__":
main()

0 comments on commit bd2af22

Please sign in to comment.