Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't include blank vcard/mecard fields #125

Merged
merged 2 commits into from
Oct 19, 2023
Merged

Conversation

missionfloyd
Copy link
Contributor

@missionfloyd missionfloyd commented Jun 15, 2023

Can result in a less dense (and thus easier to scan) code.

Before:
before

BEGIN:VCARD
VERSION:3.0
N:Doe;John;
FN:
EMAIL:john@example.com
TEL:
TEL;TYPE=FAX:
TEL;TYPE=CELL:
URL:
TITLE:
END:VCARD

After:
after

BEGIN:VCARD
VERSION:3.0
N:Doe;John;
FN:
EMAIL:john@example.com
END:VCARD

@heuer
Copy link
Owner

heuer commented Oct 17, 2023

Please provide more information how you created the QR codes.

@missionfloyd
Copy link
Contributor Author

missionfloyd commented Oct 18, 2023

Those were made with my QR code extension for stable-diffusion-webui.
https://github.com/missionfloyd/webui-qrcode-generator/blob/master/scripts/qrcode.py#L23

It works right if I exclude the empty fields or set them to None. This generates the "After" image above.

import segno
from segno import helpers

data = helpers.make_vcard_data(displayname="", name="Doe;John;", email="john@example.com")
qrcode = segno.make(data, micro=False, error="H", boost_error=False)
qrcode.save('vcard.png', scale=4)

But not if I pass it an empty string.

import segno
from segno import helpers

data = helpers.make_vcard_data(displayname="", name="Doe;John;", email="john@example.com", phone="")
qrcode = segno.make(data, micro=False, error="H", boost_error=False)
qrcode.save('vcard.png', scale=4)

Because it's explicitly checking for None, instead of falsy values.

segno/segno/helpers.py

Lines 150 to 155 in 184c7ec

def make_multifield(name, val):
if val is None:
return ()
if isinstance(val, str_type):
val = (val,)
return ['{0}:{1};'.format(name, escape(i)) for i in val]

Of course, I could work around it with a bunch of or None's.

            data = helpers.make_vcard_data(name, displayname=args["vcard_displayname"], nickname=args["vcard_nickname"], street=args["vcard_address"], city=args["vcard_city"], region=args["vcard_state"], zipcode=args["vcard_zipcode"], country=args["vcard_country"], birthday=args["vcard_birthday"], email=args["vcard_email"] or None, phone=args["vcard_phone"] or None, fax=args["vcard_fax"] or None, memo=args["vcard_memo"], org=args["vcard_organization"], title=args["vcard_title"] or None, cellphone=(args["vcard_phone_mobile"] or None), url=(args["vcard_url"] or None))

@heuer
Copy link
Owner

heuer commented Oct 18, 2023

Ok, thank you. Much better solution (testing for falsy value). I'll add a test case and merge it asap

heuer added a commit that referenced this pull request Oct 19, 2023
@heuer heuer merged commit 41c97c1 into heuer:master Oct 19, 2023
7 checks passed
@heuer
Copy link
Owner

heuer commented Oct 19, 2023

Thanks!

@missionfloyd missionfloyd deleted the vcard branch October 20, 2023 05:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants