# Path: channels/app.py
# def init_database(app):
# def init_disqus(app):
# def init_publisher(app):
# def get_client(key):


import cPickle as pickle
import datetime
import simplejson as json
import urllib
from channels.app import app, disqusapi
from disqusapi import Paginator
print 'Trying to find %s category in existing categories...' % TALK_CATEGORY_NAME
for existing_category in api(disqusapi.categories.list):
    if existing_category['title'] == TALK_CATEGORY_NAME:
        talk_category_id = existing_category['id']

if not talk_category_id:
    print "Couldn't find it, adding it..."
    new_category = api(disqusapi.categories.create, title=TALK_CATEGORY_NAME)
    talk_category_id = new_category['id']


print "Downloading list of existing threads..."
paginator = Paginator(disqusapi.threads.list, **api_args(category=talk_category_id))
existing_urls = dict((t['link'], t) for t in paginator)

print "%s existing threads found!" % len(existing_urls)

print 'Downloading and processing sessionlist...'
schedule = json.loads(urllib.urlopen('https://us.pycon.org/2012/schedule/json/').read())
schedule = [s for s in schedule if s.get('url')]

for talk in schedule:
    print ' - Processing session %s' % talk['title']

    for key in ('start', 'end', 'last_updated'):
        dt = datetime.datetime(*map(int, talk[key][0:6]))
        talk[key] = dt + datetime.timedelta(hours=5)

    if talk['url'] not in existing_urls:
        args = dict(

# Path: channels/app.py
# def init_database(app):
# def init_disqus(app):
# def init_publisher(app):
# def get_client(key):


# Path: setup_threads.py
import cPickle as pickle
import datetime
import simplejson as json
import urllib
from channels.app import app, disqusapi
from disqusapi import Paginator

print 'Trying to find %s category in existing categories...' % TALK_CATEGORY_NAME
for existing_category in api(disqusapi.categories.list):
    if existing_category['title'] == TALK_CATEGORY_NAME:
        talk_category_id = existing_category['id']

if not talk_category_id:
    print "Couldn't find it, adding it..."
    new_category = api(disqusapi.categories.create, title=TALK_CATEGORY_NAME)
    talk_category_id = new_category['id']


print "Downloading list of existing threads..."
paginator = Paginator(disqusapi.threads.list, **api_args(category=talk_category_id))
existing_urls = dict((t['link'], t) for t in paginator)

print "%s existing threads found!" % len(existing_urls)

print 'Downloading and processing sessionlist...'
schedule = json.loads(urllib.urlopen('https://us.pycon.org/2012/schedule/json/').read())
schedule = [s for s in schedule if s.get('url')]

for talk in schedule:
    print ' - Processing session %s' % talk['title']

    for key in ('start', 'end', 'last_updated'):
        dt = datetime.datetime(*map(int, talk[key][0:6]))
        talk[key] = dt + datetime.timedelta(hours=5)

    if talk['url'] not in existing_urls:
        args = dict(

            forum=app.config['DISQUS_FORUM'],