Exemplo n.º 1
0
def isAready(isbn):
    isbns = loadIsbns("./visited.csv")
    if isbn in isbns:
        return True
    else:
        return False
from Download import Download

def worker(appids, isbns, appidsCycle):
    # appidsCycle = cycle(appids)

    for isbn in isbns:
        url = 'http://' + appidsCycle.next() + '.appspot.com/url?url=' + 'http://book.douban.com/isbn/' + str(isbn)
        # print 'DEBUG: ', url

        d = Download(url)
        if d.doRequest():
            print isbn, 'network error'
            continue

        j = json.loads(d.getSOURCE())
        print isbn, j['status_code']

    return

if __name__ == '__main__':
    isbns = loadIsbns('isbns.txt')
    appids = loadIsbns('appids')
    appidsCycle = cycle(appids)

    jobs = []
    for i in range(10):
        # print len(appids)
        p = multiprocessing.Process(target=worker,args = (appids, isbns[(800 * i):(i * 800 + 800)], appidsCycle))
        jobs.append(p)
        p.start()