from olapi import OpenLibrary
import simplejson as json
from collections import defaultdict
from catalog.read_rc import read_rc
from catalog.utils.query import query, query_iter, set_staging, base_url
from catalog.utils import mk_norm, get_title
from six.moves import urllib

import six

sys.stdout = codecs.getwriter('utf-8')(sys.stdout)
set_staging(True)

rc = read_rc()

ol = OpenLibrary(base_url())
ol.login('EdwardBot', rc['EdwardBot'])

re_year = re.compile('(\d{3,})$')

queue = []


def iter_works(fields):
    q = {'type': '/type/work', 'key': None}
    for f in fields:
        q[f] = None
    return query_iter(q)


def dates():
#!/usr/local/bin/python2.5
import sys, urllib, re, codecs
sys.path.append('/home/edward/src/olapi')
from olapi import OpenLibrary
import simplejson as json
from collections import defaultdict
from catalog.read_rc import read_rc
from catalog.utils.query import query, query_iter, set_staging, base_url
from catalog.utils import mk_norm, get_title

sys.stdout = codecs.getwriter('utf-8')(sys.stdout)
set_staging(True)

rc = read_rc()

ol = OpenLibrary(base_url())
ol.login('EdwardBot', rc['EdwardBot'])

re_year = re.compile('(\d{3,})$')

queue = []

def iter_works(fields):
    q = { 'type':'/type/work', 'key': None }
    for f in fields: q[f] = None
    return query_iter(q)

def dates():
    f = 'first_publish_date'
    for w in iter_works([f, 'title']):
        if f in w: