使用 pidgin dbus python api 获取 xmpp 资源字符串

发布于 2024-12-20 09:25:45 字数 800 浏览 2 评论 0原文

我使用 pidgin dbus api 通过编写以下 python 代码片段来打印我的 gtalk 好友的名称及其状态:

import dbus


# Initiate a connection to the Session Bus
bus = dbus.SessionBus()

# Associate Pidgin's D-Bus interface with Python objects
obj = bus.get_object("im.pidgin.purple.PurpleService", "/im/pidgin/purple/PurpleObject")
purple = dbus.Interface(obj, "im.pidgin.purple.PurpleInterface")


# Iterate through every active account
for acctID in purple.PurpleAccountsGetAllActive():
   for buddy in purple.PurpleFindBuddies(acctID,""):
      print purple.PurpleBuddyGetName(buddy),'Online' if purple.PurpleBuddyIsOnline(buddy) else 'Offline'

在 Pidgin 中,当我将鼠标悬停在特定好友上时,它还会显示该好友的资源字符串,例如 < strong>gtalk、android 等.. 它告诉我用户从哪个资源登录。

有没有办法使用 pidgins dbus api 或其他方式获取此资源字符串?

请帮忙 谢谢

I was using the pidgin dbus api to print the names of my gtalk buddies and their status by writing the following python code snippet:

import dbus


# Initiate a connection to the Session Bus
bus = dbus.SessionBus()

# Associate Pidgin's D-Bus interface with Python objects
obj = bus.get_object("im.pidgin.purple.PurpleService", "/im/pidgin/purple/PurpleObject")
purple = dbus.Interface(obj, "im.pidgin.purple.PurpleInterface")


# Iterate through every active account
for acctID in purple.PurpleAccountsGetAllActive():
   for buddy in purple.PurpleFindBuddies(acctID,""):
      print purple.PurpleBuddyGetName(buddy),'Online' if purple.PurpleBuddyIsOnline(buddy) else 'Offline'

In Pidgin when i hover my mouse over a particular buddy, it also shows the Resource string of that buddy for example gtalk, android etc... which tells me which resource the user is logged in from.

Is there a way to fetch this Resource string using pidgins dbus api or some other way ?

Please Help
Thank You

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

赠意 2024-12-27 09:25:45

您可以使用 wiki 页面 中的脚本:

#!/usr/bin/env python

def my_func(account, sender, message, conversation, flags):
    print sender, "said:", message

import dbus, gobject
from dbus.mainloop.glib import DBusGMainLoop
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
bus = dbus.SessionBus()

bus.add_signal_receiver(my_func,
                        dbus_interface="im.pidgin.purple.PurpleInterface",
                        signal_name="ReceivedImMsg")

loop = gobject.MainLoop()
loop.run()

sender 这里将是像这样:
'[email protected]/androidXXXXXXXX' 如果使用 android 或
'[email protected]/gmail.XXXXXXXX' 用于 gtalk 或
'[email protected]/XXXXXXXX' 对于其他即时消息,其中 X 是十六进制值。

you can use the script from the wiki page:

#!/usr/bin/env python

def my_func(account, sender, message, conversation, flags):
    print sender, "said:", message

import dbus, gobject
from dbus.mainloop.glib import DBusGMainLoop
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
bus = dbus.SessionBus()

bus.add_signal_receiver(my_func,
                        dbus_interface="im.pidgin.purple.PurpleInterface",
                        signal_name="ReceivedImMsg")

loop = gobject.MainLoop()
loop.run()

sender here will be smth like this:
'[email protected]/androidXXXXXXXX' in case of using android or
'[email protected]/gmail.XXXXXXXX' for gtalk or
'[email protected]/XXXXXXXX' for other im, where X is a hex value.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文