File: mecard.py

package info (click to toggle)
python-qrcode 5.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 224 kB
  • ctags: 179
  • sloc: python: 1,317; makefile: 4
file content (33 lines) | stat: -rw-r--r-- 912 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import six

# {'code': 'N', 'label': 'Name', 'required': True, 'multipart': [
#     'Last Name', 'First Name']},
PROPERTIES = {
    'NICKNAME': {'label': 'Nickname'},
    'BDAY': {'label': 'Birthday', 'date': True},
    'TEL': {'label': 'Phone'},
    'EMAIL': {'label': 'E-mail'},
    'ADR': {'label': 'Address', 'multipart': [
        'PO Box', 'Room Number', 'House Number', 'City', 'Prefecture',
        'Zip Code', 'Country']},
    'URL': {'label': 'URL'},
    'MEMO': {'label': 'Note'},
}


def build_code(data):
    notation = []

    name = data['N']
    if not isinstance(name, six.text_type):
        name = ','.join(name)
    notation.append('N', name)

    for prop in PROPERTIES:
        value = data.get(prop['code'])
        if not value:
            continue
        if prop['date']:
            value = value.strftime('%Y%m%d')
        elif prop['multipart']:
            value = ','.join(value)