Exemple #1
0
def add_cover_image(key, ia):
    if has_cover_retry(key):
        print key, 'has_cover'
    ret = find_img(ia)

    print 'cover image:', ret
    post(key, ia, ret)
Exemple #2
0
def add_cover_image(ekey, ia):
#    if has_cover_retry(key):
#        print key, 'has_cover'
#        return
    h1 = httplib.HTTPConnection('openlibrary.org')
    body = json.dumps(dict(username='******', password=rc['ImportBot']))
    headers = {'Content-Type': 'application/json'}  
    h1.request('POST', 'http://openlibrary.org/account/login', body, headers)

    res = h1.getresponse()

    res.read()
    assert res.status == 200
    cookies = res.getheader('set-cookie').split(',')
    cookie =  ';'.join([c.split(';')[0] for c in cookies])
    #print 'cookie:', cookie

    cover_url = 'http://www.archive.org/download/' + ia + '/page/' + ia + '_preview.jpg'
    body = urllib.urlencode({"url": cover_url})
    assert ekey.startswith('/books/')
    add_cover_url = 'http://openlibrary.org' + ekey + '/add-cover.json'
    #print cover_url
    #print add_cover_url
    h1.request('POST', add_cover_url, body, {'Cookie': cookie})
    res = h1.getresponse()
    res.read()
    return

    ret = find_img(ia)

    if not ret:
        return
    print 'cover image:', ret
    post(ekey, ia, ret)
Exemple #3
0
def add_cover_image(key, ia):
    if has_cover_retry(key):
        print key, 'has_cover'
        return
    cover_url = 'http://www.archive.org/download/' + ia + '/page/' + ia + '_preview.jpg'
    post_data = urllib.urlencode({"url": cover_url})
    if key.startswith('/b/'):
        key = '/books/' + key[3:]
    ol._request(key + "/add-cover.json", method="POST", data=post_data)
    return

    ret = find_img(ia)

    if not ret:
        return
    print 'cover image:', ret
    post(key, ia, ret)