# Path: shownotes/models.py
# class Show(models.Model):
#     id = models.IntegerField(primary_key=True)
#     name = models.TextField()
#     last_updated = models.DateTimeField()
# 
#     def __unicode__(self):
#         return u'{}: {}'.format(self.id, self.name)
# 
#     @classmethod
#     def exists(cls, number):
#         return Show.objects.filter(pk=number).count() == 1
# 
# 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 Show, ShowSource
from django.core.management.base import BaseCommand
from collections import deque
from threading import Thread
import shownotes.management.loaders as loaders
import common.netutils as netutils
import time
import re
                    import traceback
    main_url = 'http://{}.nashownotes.com'
    shownote_url = 'http://{}.nashownotes.com/shownotes'
    for number in reversed(xrange(SHOWNOTE_CUTOFF, show_number + 1)):
        if number in BAD_LIST:
            continue
        if not Show.exists(number):
            if ShowSource.exists(number):
                HTML_LIST.append(number)
                continue
            if number < direct_cutoff:
                url = shownote_url.format(number)
            else:
                url = main_url.format(number)
            try:
                text = netutils.get_html(url)
            except:
                print('Error loading html from: {}'.format(url))
                continue

            # check for opml links
            opml_links = netutils.get_links_to('^http://.*\.opml$', text)
            if len(opml_links) > 0:
                assert(len(opml_links) == 1)
                try:
                    opml = netutils.get_html(opml_links[0])
                except:
                    print('Error loading opml from: {}'.format(
                        opml_links[0]))
                    continue
                print('   -> {} opml'.format(number))

# Path: shownotes/models.py
# class Show(models.Model):
#     id = models.IntegerField(primary_key=True)
#     name = models.TextField()
#     last_updated = models.DateTimeField()
# 
#     def __unicode__(self):
#         return u'{}: {}'.format(self.id, self.name)
# 
#     @classmethod
#     def exists(cls, number):
#         return Show.objects.filter(pk=number).count() == 1
# 
# 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: shownotes/management/commands/full_update.py
from shownotes.models import Show, ShowSource
from django.core.management.base import BaseCommand
from collections import deque
from threading import Thread
import shownotes.management.loaders as loaders
import common.netutils as netutils
import time
import re
                    import traceback

    main_url = 'http://{}.nashownotes.com'
    shownote_url = 'http://{}.nashownotes.com/shownotes'
    for number in reversed(xrange(SHOWNOTE_CUTOFF, show_number + 1)):
        if number in BAD_LIST:
            continue
        if not Show.exists(number):
            if ShowSource.exists(number):
                HTML_LIST.append(number)
                continue
            if number < direct_cutoff:
                url = shownote_url.format(number)
            else:
                url = main_url.format(number)
            try:
                text = netutils.get_html(url)
            except:
                print('Error loading html from: {}'.format(url))
                continue

            # check for opml links
            opml_links = netutils.get_links_to('^http://.*\.opml$', text)
            if len(opml_links) > 0:
                assert(len(opml_links) == 1)
                try:
                    opml = netutils.get_html(opml_links[0])
                except:
                    print('Error loading opml from: {}'.format(
                        opml_links[0]))
                    continue
                print('   -> {} opml'.format(number))

                ShowSource(filetype=ShowSource.OPML, text=opml,