python, dbus to change multiple accounts status
Eion Robb
eion at robbmob.com
Sun Oct 7 14:19:36 EDT 2018
Hi Claudio,
Your question is a bit more of a devel question than a support one, so
cc'ing in the devel list.
You might find it easier to use the 'savedstatus' API, so that you're not
having to fluff around with presences and status.
https://developer.pidgin.im/doxygen/2.7.11/html/savedstatuses_8h.html
I don't know the Python/dbus API well enough, but the C code for what
you're trying to do is:
PurpleSavedStatus *saved_status;
PurpleStatusPrimitive primitive = PURPLE_STATUS_UNAVAILABLE;
const gchar *message = "claudio using resource5";
saved_status =
purple_savedstatus_find_transient_by_type_and_message(primitive, message);
if (saved_status == NULL) {
saved_status = purple_savedstatus_new(NULL, primitive);
purple_savedstatus_set_message(saved_status, message);
}
purple_savedstatus_activate(saved_status);
Let us know how it goes :)
Cheers,
Eion
On Sun, 7 Oct 2018 at 02:07, Claudio <claudio.fontana at gliwa.com> wrote:
>
>
>
> >
> > #! /usr/bin/python3
> >
> > import sys
> > import dbus
> > from pydbus import SessionBus
> >
> > def usage():
> > text = '''
> > ./presence.py busy FIRSTNAME ACCOUNT
> > ./presence.py avail FIRSTNAME ACCOUNT
> >
> > FIRSTNAME: first name.
> > ACCOUNT: the alias of the account presence to change
> >
> > Example:
> >
> > ./presence.py busy claudio resource5
> > --> sets resource5 to busy with msg: "claudio using
> resource5"
> > ./presence.py avail claudio resource5
> > --> claudio frees up resource5, status set to avail.
> > '''
> > print(text)
> > sys.exit(1)
> >
> > #sys.argv = ["./presence.py", "busy", "claudio", "resource5"]
> >
> > if len(sys.argv) != 4:
> > print(len(sys.argv))
> > usage()
> >
> > if (sys.argv[1]) == "busy":
> > arg_status = "Do Not Disturb"
> > elif (sys.argv[1]) == "avail":
> > arg_status = "Available"
> > else:
> > usage()
> >
> > arg_firstname = sys.argv[2]
> > arg_account = sys.argv[3]
> >
> > print("presence: connecting to PurpleService")
> >
> > bus = SessionBus()
> > try:
> > p = bus.get("im.pidgin.purple.PurpleService",
> > "/im/pidgin/purple/PurpleObject")
> > except:
> > sys.exit("presence: failed to connect to PurpleService")
> >
> > accounts = p.PurpleAccountsGetAll()
> >
> > if len(accounts) == 0:
> > sys.exit("presence: no account found.")
> >
> > for account in accounts:
> > alias = p.PurpleAccountGetAlias(account)
> > print(alias + " is accountid " + str(account))
> > if (alias != arg_account):
> > print("presence: skipping account " + alias)
> > continue
> >
> > print("presence: found account " + alias)
> >
> > presence = p.PurpleAccountGetPresence(account)
> > status = p.PurplePresenceGetActiveStatus(presence)
> > status_type = p.PurpleStatusGetType(status)
> > status_type_name = p.PurpleStatusTypeGetName(status_type)
> >
> > if (status_type_name == arg_status):
> > sys.exit("presence: account is already " + arg_status)
> >
> > status_type_list = p.PurpleAccountGetStatusTypes(account)
> > status_id = "";
> >
> > for status_type in status_type_list:
> > status_type_name = p.PurpleStatusTypeGetName(status_type)
> > print("status_type_name in status_type_list = " +
> status_type_name)
> > if (status_type_name == arg_status):
> > status_id = p.PurpleStatusTypeGetId(status_type)
>
> here I am missing a
> break;
>
> (just noticed). Does not fix the problem though, my script seems to run
> consistently,
> but the client (finch) does not show any changes in my status.
>
> _______________________________________________
> Support at pidgin.im mailing list
> Want to unsubscribe? Use this link:
> https://pidgin.im/cgi-bin/mailman/listinfo/support
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://pidgin.im/pipermail/support/attachments/20181008/cacc7c11/attachment.html>
More information about the Support
mailing list