# Path: shownotes/models.py
# class ShowSource(models.Model):
#     OPML = 'opml'
#     HTML = 'html'
#     SOURCE_CHOICES = ((OPML, 'opml'), (HTML, 'html'))
#     filetype = models.CharField(max_length=4, choices=SOURCE_CHOICES)
#     text = models.TextField()
#     show_number = models.IntegerField(unique=True)
# 
#     @classmethod
#     def exists(cls, number):
#         return ShowSource.objects.filter(show_number=number).count() == 1


from shownotes.models import ShowSource
from BeautifulSoup import BeautifulSoup
import requests
import feedparser
import re
    soup = BeautifulSoup(html)
    links = [x['href'] for x in soup.findAll(
        '', {'href': re.compile(pattern)})]
    return list(set(links))


def extract_urls_from_html(html):
    '''
    extracts all urls linked to from a given html document
    '''
    soup = BeautifulSoup(html)
    return [x['href'] for x in soup.find_all('a', href=True)]


def insert_show_source(url, number):
    opml_pattern = '^http://.*\.opml'
    opml_re = re.compile(opml_pattern)

    if not opml_re.match(url):
        text = get_html(url)
        opml_urls = get_links_to(opml_pattern, text)
        assert len(opml_urls) <= 1
        if len(opml_urls) == 0:
            ShowSource(show_number=number, filetype=ShowSource.HTML,
                       text=text).save()
            return True
        else:
            url = opml_urls[0]
    if opml_re.match(url):
        text = get_html(url)

# Path: shownotes/models.py
# class ShowSource(models.Model):
#     OPML = 'opml'
#     HTML = 'html'
#     SOURCE_CHOICES = ((OPML, 'opml'), (HTML, 'html'))
#     filetype = models.CharField(max_length=4, choices=SOURCE_CHOICES)
#     text = models.TextField()
#     show_number = models.IntegerField(unique=True)
# 
#     @classmethod
#     def exists(cls, number):
#         return ShowSource.objects.filter(show_number=number).count() == 1


# Path: common/netutils.py
from shownotes.models import ShowSource
from BeautifulSoup import BeautifulSoup
import requests
import feedparser
import re

    soup = BeautifulSoup(html)
    links = [x['href'] for x in soup.findAll(
        '', {'href': re.compile(pattern)})]
    return list(set(links))


def extract_urls_from_html(html):
    '''
    extracts all urls linked to from a given html document
    '''
    soup = BeautifulSoup(html)
    return [x['href'] for x in soup.find_all('a', href=True)]


def insert_show_source(url, number):
    opml_pattern = '^http://.*\.opml'
    opml_re = re.compile(opml_pattern)

    if not opml_re.match(url):
        text = get_html(url)
        opml_urls = get_links_to(opml_pattern, text)
        assert len(opml_urls) <= 1
        if len(opml_urls) == 0:
            ShowSource(show_number=number, filetype=ShowSource.HTML,
                       text=text).save()
            return True
        else:
            url = opml_urls[0]
    if opml_re.match(url):
        text = get_html(url)

        ShowSource(show_number=number, filetype=ShowSource.OPML,