def get_blockchain(): cached_blockchain = cache.get('blockchain') if not cached_blockchain: miners_wallet = wallet.Wallet() utils.generate_qrcode( private_key=miners_wallet.private_key, blockchain_address=miners_wallet.blockchain_address, port=app.config['port']) cache['blockchain'] = blockchain.BlockChain( blockchain_address=miners_wallet.blockchain_address, port=app.config['port']) app.logger.warning({ 'private_key': miners_wallet.private_key, 'public_key': miners_wallet.public_key, 'blockchain_address': miners_wallet.blockchain_address }) return cache['blockchain']
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)
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)