MCPcopy Index your code
hub / github.com/tinode/chat / makeTheCard

Function makeTheCard

tn-cli/utils.py:44–84  ·  view source on GitHub ↗
(fn, note, photofile)

Source from the content-addressed store, hash-verified

42
43# Pack name, description, and avatar into a theCard.
44def makeTheCard(fn, note, photofile):
45 card = None
46
47 if (fn != None and fn.strip() != "") or photofile != None or note != None:
48 card = {}
49 if fn != None:
50 fn = fn.strip()
51 card['fn'] = TINODE_DEL if fn == DELETE_MARKER or fn == '' else fn
52
53 if note != None:
54 note = note.strip()
55 card['note'] = TINODE_DEL if note == DELETE_MARKER or note == '' else note
56
57 if photofile != None:
58 if photofile == '' or photofile == DELETE_MARKER:
59 # Delete the avatar.
60 card['photo'] = {
61 'data': TINODE_DEL
62 }
63 else:
64 try:
65 f = open(photofile, 'rb')
66 # File extension is used as a file type
67 mimetype = mimetypes.guess_type(photofile)
68 if mimetype[0]:
69 mimetype = mimetype[0].split("/")[1]
70 else:
71 mimetype = 'jpeg'
72 data = base64.b64encode(f.read())
73 # python3 fix.
74 if type(data) is not str:
75 data = data.decode()
76 card['photo'] = {
77 'data': data,
78 'type': mimetype
79 }
80 f.close()
81 except IOError as err:
82 stdoutln("Error opening '" + photofile + "':", err)
83
84 return card
85
86
87# Create drafty representation of a message with an inline image.

Callers 3

accMsgFunction · 0.90
subMsgFunction · 0.90
setMsgFunction · 0.90

Calls 1

stdoutlnFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…