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

Creating a multiple URL vCard using vObject #167

Open
meet-VC opened this issue Apr 19, 2021 · 1 comment
Open

Creating a multiple URL vCard using vObject #167

meet-VC opened this issue Apr 19, 2021 · 1 comment

Comments

@meet-VC
Copy link

meet-VC commented Apr 19, 2021

How can I get multiple URL in one VCard.

I want to create a VCard with details like:

  • Fname
  • Lname
  • Company name
  • Phone number
  • address
  • website url
  • facebook url
  • insta gram url
  • Tik tok url
  • twitter url

I tried the following code

	vCard.add('URL')
	vCard.url.value = 'https://www.example.com'
	vCard.url.type_param = "Website:"

	vCard.add('URL')
	vCard.url.value = 'https://www.facebook.com'
	vCard.url.type_param = "Facebook:"

In the output I was only able to get one of the link:

BEGIN:VCARD
VERSION:3.0
EMAIL;TYPE=INTERNET:[email protected]
FN:Justin
N:White;Justin;;;
ORG:Tesla
TEL;TYPE=HOME:+16503977339
URL;TYPE=Facebook:https://www.facebook.com
URL:
END:VCARD
@brandon-clair
Copy link

@meet-VC You'll have to construct an initial "URL" component, and then manually append additional children to the component list, which is hinted at in the readme.

Similar to parameters, If you want to access more than just the first child of a Component, you can access the full list of children of a given name by appending _list to the attribute name:

Since "URL" components don't have a constructor class (as opposed to "N", which has vobject.vcard.Name()), you'll also have to manually build the children you want to append with vobject.base.ContentLine(). The ContentLine docstring is misleading when it states that its params argument is a dictionary. It actually requires a list of lists.

Here's how I made multiple URLs:

>>> import vobject
>>> card = vobject.vCard()
>>> card.add('n')
<N{}    >
>>> card.add('fn')
<FN{}>
>>> card.add('url')
<URL{}>
>>> card.url.value = 'https://www.example.com'
>>> card.url.type_param = 'Website:'
>>> card.url_list.append(vobject.base.ContentLine('URL', [['TYPE:','Facebook:']], 'https://www.facebook.com'))
>>> card.serialize()
'BEGIN:VCARD\r\nVERSION:3.0\r\nFN:\r\nN:;;;;\r\nURL;TYPE="Website:":https://www.example.com\r\nURL;TYPE:="Facebook:":https://www.facebook.com\r\nEND:VCARD\r\n'

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

No branches or pull requests

2 participants