MCPcopy Index your code
hub / github.com/wechaty/python-wechaty / display_contacts

Function display_contacts

examples/contact-bot.py:32–58  ·  view source on GitHub ↗

Display all the contacts and dump the avatars

()

Source from the content-addressed store, hash-verified

30
31
32async def display_contacts() -> None:
33 """Display all the contacts and dump the avatars"""
34 # pylint: disable=W0603
35 global bot
36 assert bot is not None
37 while True:
38 contacts = await bot.Contact.find_all()
39
40 log.info('#######################')
41 log.info('Contact number: %s\n', len(contacts))
42
43 for index, contact in enumerate(contacts):
44 if contact.type() == ContactType.CONTACT_TYPE_PERSONAL:
45 log.info('personal %s: %s : %s', index, contact.name, contact.get_id())
46
47 for contact in contacts[:MAX_CONTACTS]:
48 file = await contact.avatar()
49 name = file.name
50 await file.to_file(name, True)
51
52 log.info('Contact: "%s" with avatar file: "%s"', contact.name, name)
53
54 if len(contacts) > MAX_CONTACTS:
55 log.info('Too many contacts. I only show you the first %s ones...', MAX_CONTACTS)
56
57 log.info('I will re-dump contact weixin id & names after %s second... ', INTERVAL)
58 await asyncio.sleep(INTERVAL)
59
60
61async def handle_login(user: Contact) -> None:

Callers 1

handle_loginFunction · 0.85

Calls 4

find_allMethod · 0.45
typeMethod · 0.45
get_idMethod · 0.45
avatarMethod · 0.45

Tested by

no test coverage detected