Ejemplo n.º 1
0
def generate_batch(batch):
    host = 'http://112.124.117.97'
    zip_dir = '/usr/share/nginx/html'

    import tempfile
    to_dir = tempfile.mkdtemp()
    print to_dir

    # generate all qrcode in that temp dir
    for i in xrange(1, int(batch.count)+1):
        record = Record(batch=batch, index=i,
                        serial_num=utils.generate_serial_num(),
                        left_time=batch.verify_time)
        record.save()

        url = urlparse.urljoin(host, record.serial_num)
        filepath = os.path.join(to_dir, record.serial_num + '.png')
        utils.generate_qrcode(url, filepath)

    zip_filepath = os.path.join(zip_dir, batch.bid + '.zip')
    utils.zipdir(to_dir, zip_filepath)

    utils.safe_rmtree(to_dir)
Ejemplo n.º 2
0
if __name__ == '__main__':
    connect('paibei')

    host = 'http://112.124.117.97'
    zip_dir = '/tmp/qrcode'

    import tempfile
    to_dir = tempfile.mkdtemp()
    print to_dir

    batch_id = sys.argv[1]
    added_count = sys.argv[2]

    batch = get_batch(batch_id)
    currentIndex = batch.count
    # query current record index in batch
    for i in xrange(currentIndex + 1, currentIndex + added_count + 1):
        record = Record(batch=batch, index=i,
                        serial_num=utils.generate_serial_num(),
                        left_time=batch.verify_time)
        record.save()

        url = urlparse.urljoin(host, batch.bid)
        filepath = os.path.join(to_dir, record.serial_num + '.png')
        utils.generate_qrcode(url, filepath)

    zip_filepath = os.path.join(zip_dir, batch.bid + '.zip')
    utils.zipdir(to_dir, zip_filepath)

    utils.safe_rmtree(to_dir)