Skip to content

Instantly share code, notes, and snippets.

@sirpoot
Last active August 29, 2015 14:08
Show Gist options
  • Save sirpoot/ea37bd76de26c0693739 to your computer and use it in GitHub Desktop.
Save sirpoot/ea37bd76de26c0693739 to your computer and use it in GitHub Desktop.
'''
Copyright (c) <2012> Tarek Galal <[email protected]>
Permission is hereby granted, free of charge, to any person obtaining a copy of this
software and associated documentation files (the "Software"), to deal in the Software
without restriction, including without limitation the rights to use, copy, modify,
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR
A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
'''
import os
parentdir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
os.sys.path.insert(0,parentdir)
import time
from Yowsup.connectionmanager import YowsupConnectionManager
# sirpoot
class GroupInfoClient:
def __init__(self, jid, waitForReceipt=False):
self.jids = []
phoneNumber = jid
if '-' in phoneNumber:
self.jid = "%[email protected]" % phoneNumber
else:
self.jid = "%[email protected]" % phoneNumber
self.waitForReceipt = waitForReceipt
connectionManager = YowsupConnectionManager()
self.signalsInterface = connectionManager.getSignalsInterface()
self.methodsInterface = connectionManager.getMethodsInterface()
self.signalsInterface.registerListener("auth_success", self.onAuthSuccess)
self.signalsInterface.registerListener("auth_fail", self.onAuthFailed)
if waitForReceipt:
self.signalsInterface.registerListener("receipt_messageSent", self.onMessageSent)
self.gotReceipt = False
self.signalsInterface.registerListener("disconnected", self.onDisconnected)
self.signalsInterface.registerListener("group_gotInfo", self.groupGotInfo)
self.done = False
def login(self, username, password):
self.username = username
self.methodsInterface.call("auth_login", (username, password))
while not self.done:
time.sleep(0.5)
def onAuthSuccess(self, username):
print("Authed %s" % username)
if self.waitForReceipt:
self.methodsInterface.call("ready")
self.methodsInterface.call("group_getInfo", (self.jid, 1))
print("Sent get group info")
if self.waitForReceipt:
timeout = 5
t = 0;
while t < timeout and not self.gotReceipt:
time.sleep(0.5)
t+=1
self.done = True
def onAuthFailed(self, username, err):
print("Auth Failed!")
def onDisconnected(self, reason):
print("Disconnected because %s" %reason)
def onMessageSent(self, jid, messageId):
self.gotReceipt = True
pass
def groupGotInfo(self, jid, owner, subject, subjectOwner, subjectT, creation):
print "---------------"
print "Group info"
print "---------------"
print "JID :", jid
print "Owner :", owner
print "Creation :", creation
print "Subject :", subject
print "Subject owner :", subjectOwner
print "Subject time :", subjectT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment