#!/usr/bin/env python3
import io
import os
import sys

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
VENDOR_DIR = os.path.join(BASE_DIR, 'python_vendor')
if VENDOR_DIR not in sys.path:
    sys.path.insert(0, VENDOR_DIR)

import qrcode
from qrcode.image.svg import SvgPathImage


def main() -> int:
    if len(sys.argv) < 2:
        return 2
    data = sys.argv[1]
    qr = qrcode.QRCode(
        version=None,
        error_correction=qrcode.constants.ERROR_CORRECT_M,
        box_size=10,
        border=2,
    )
    qr.add_data(data)
    qr.make(fit=True)
    img = qr.make_image(image_factory=SvgPathImage)
    out = io.BytesIO()
    img.save(out)
    sys.stdout.write(out.getvalue().decode('utf-8'))
    return 0


if __name__ == '__main__':
    raise SystemExit(main())
