def encode(ctx, string, verbose): """ Encodes a string into a QR code. """ if verbose: click.echo("Encoding your message...") _target = get_qr(string, ctx.obj["target"], ctx.obj["size"]) if verbose: click.echo(click.style("Your QR code has been saved to {_target}.".format(_target=_target), fg="green"))
def vcard(verbose=True, ctx=None, target=None, size=None, template_location="featherqr/vcard.template", suppress_qr=False, **kwargs): """ Creates a vcard and a QR code encoding from particular attributes to a vcard. :param verbose: Determines whether operational messages are displayed :type verbose: bool :param ctx: click context, if invoked in the command line interface. :type ctx: click.Context :param target: Target file name :type target: str :param size: Size of resulting QR code image in pixels. :type size: int :param template_location: Location of template. :type template_location: str :param suppress_qr: Suppresses QR code generation. :type suppress_qr: bool :return: Filename of the resulting vcard. :rtype: str **vCard keyword arguments**: :param firstname: First name :type firstname: str :param lastname: Last name :type lastname: str :param title: Job title :type title: str :param org: Organization :type org: str :param workphone: Work telephone number, incl. country code :type workphone: str :param homephone: Home telephone number, incl. country code :type homephone: str :param cellphone: Mobile telephone number, incl. country code :type cellphone: str :param workemail: Work e-mail address :type workemail: str :param personalemail: Personal e-mail address :type personalemail: str :param workaddress: Work address, separated by semicola :type workaddress: str :param homeaddress: Home address, separated by semicola :type homeaddress: str :param url: URL, e.g. of own website :type url: str This function generates a complete vCard that adheres to the specifications in `RFC6350 <https://tools.ietf.org/html/rfc6350>`_. Unless the ``suppress_qr`` flag is set, a PNG formatted QR code version of the vCard will also be generated. The function returns the path of the generated vCard. """ check_for_names(kwargs) template = Template(open(template_location).read()) _vcard = template.render(kwargs) print(_vcard) if verbose: click.echo(click.style("This is your vCard:", underline=True, fg="blue")) click.echo(_vcard + "\n") _target = ctx.obj.get("target", target) _vcard_filename = generate_filename_from_target(_target) if _target else generate_random_filename(kwargs) write_vcard(_vcard, _vcard_filename, verbose) if not suppress_qr: get_qr(_vcard, target=_vcard_filename.replace("vcard", "png")) if verbose: click.echo(click.style("QR code generated and saved as {target:}.".format( target=_vcard_filename.replace('vcard', 'png')), fg="green") ) return os.path.join(getcwd(), _vcard_filename)