Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import argparse, sys, os, csv
- from Yowsup.Common.utilities import Utilities
- from Yowsup.Common.debugger import Debugger
- from Yowsup.Common.constants import Constants
- from Yowsup.Registration.v2.existsrequest import WAExistsRequest as WAExistsRequestV2
- from Yowsup.Registration.v2.coderequest import WACodeRequest as WACodeRequestV2
- from Yowsup.Registration.v2.regrequest import WARegRequest as WARegRequestV2
- from Yowsup.Contacts.contacts import WAContactsSyncRequest
- from Yowsup.connectionmanager import YowsupConnectionManager
- import threading,time, base64
- DEFAULT_CONFIG = "yowsup.conf"
- COUNTRIES_CSV = "countries.csv"
- # Message execution
- def executeMessage(rid, message):
- if not (rid in whitelist):
- return
- if message == "Hi":
- message_send(rid, "Hi \n I'm WhatsAPee")
- return
- def dissectPhoneNumber(phoneNumber):
- try:
- with open(COUNTRIES_CSV, 'r') as csvfile:
- reader = csv.reader(csvfile, delimiter=',')
- for row in reader:
- if len(row) == 3:
- country, cc, mcc = row
- else:
- country,cc = row
- mcc = "000"
- try:
- if phoneNumber.index(cc) == 0:
- print("Detected cc: %s"%cc)
- return (cc, phoneNumber[len(cc):])
- except ValueError:
- continue
- except:
- pass
- return False
- def getCredentials(config = DEFAULT_CONFIG):
- if os.path.isfile(config):
- print("Found config")
- f = open(config)
- phone = ""
- idx = ""
- pw = ""
- cc = ""
- try:
- for l in f:
- line = l.strip()
- if len(line) and line[0] not in ('#',';'):
- prep = line.split('#', 1)[0].split(';', 1)[0].split('=', 1)
- varname = prep[0].strip()
- val = prep[1].strip()
- if varname == "phone":
- phone = val
- elif varname == "id":
- idx = val
- elif varname =="password":
- pw =val
- elif varname == "cc":
- cc = val
- return (cc, phone, idx, pw);
- except:
- pass
- else:
- sys.exit("Found no config")
- return 0
- def onAuthSuccess(username):
- print("Authed %s" % username)
- methodsInterface.call("ready")
- def onAuthFailed(username, err):
- sys.exit("Auth Failed!")
- def onDisconnected(reason):
- sys.exit("Disconnected because %s" %reason)
- def onPresenceUpdated(self, jid, lastSeen):
- formattedDate = datetime.datetime.fromtimestamp(long(time.time()) - lastSeen).strftime('%d-%m-%Y %H:%M')
- onMessageReceived(0, jid, "LAST SEEN RESULT: %s"%formattedDate, long(time.time()), False, None, False)
- def onMessageSent(jid, messageId):
- formattedDate = datetime.datetime.fromtimestamp(sentCache[messageId][0]).strftime('%d-%m-%Y %H:%M')
- print("%s [%s]:%s"%(username, formattedDate, sentCache[messageId][1]))
- def onMessageReceived(messageId, jid, messageContent, timestamp, wantsReceipt, pushName, isBroadcast):
- if jid[:jid.index('@')] != phoneNumber:
- return
- formattedDate = datetime.datetime.fromtimestamp(timestamp).strftime('%d-%m-%Y %H:%M')
- print("%s [%s]:%s"%(jid, formattedDate, messageContent))
- executeMessage(jid, messageContent)
- #Autopings einschalten
- ycm = YowsupConnectionManager()
- ycm.setAutoPong(True)
- credentials = getCredentials(DEFAULT_CONFIG)
- countryCode, login, identity, password = credentials
- identity = Utilities.processIdentity(identity)
- password = base64.b64decode(bytes(password.encode('utf-8')))
- if countryCode:
- phoneNumber = login[len(countryCode):]
- else:
- dissected = dissectPhoneNumber(login)
- if not dissected:
- sys.exit("ERROR. Couldn't detect cc, you have to manually place it your config")
- countryCode, phoneNumber = dissected
- username=phoneNumber + "@s.whatsapp.net"
- whitelist=["69911301815@s.whatsapp.net"]
- signalsInterface = ycm.getSignalsInterface()
- methodsInterface = ycm.getMethodsInterface()
- signalsInterface.registerListener("auth_success", onAuthSuccess)
- signalsInterface.registerListener("auth_fail", onAuthFailed)
- signalsInterface.registerListener("message_received", onMessageReceived)
- signalsInterface.registerListener("receipt_messageSent", onMessageSent)
- signalsInterface.registerListener("presence_updated", onPresenceUpdated)
- signalsInterface.registerListener("disconnected", onDisconnected)
- methodsInterface.call("auth_login", (username, password))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement