Comment out import contacts from Bot.py
This is interfering with testing.
This commit is contained in:
parent
97c3aba3ec
commit
f40f077270
108
bot.py
108
bot.py
|
@ -31,7 +31,7 @@ import os
|
||||||
import utils
|
import utils
|
||||||
|
|
||||||
from constants import *
|
from constants import *
|
||||||
from googleclient import GoogleClient
|
#from googleclient import GoogleClient
|
||||||
|
|
||||||
from Yowsup.Contacts.contacts import WAContactsSyncRequest
|
from Yowsup.Contacts.contacts import WAContactsSyncRequest
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ class Bot():
|
||||||
self.google = GoogleClient()
|
self.google = GoogleClient()
|
||||||
|
|
||||||
self.commands = {
|
self.commands = {
|
||||||
"import": self._import,
|
# "import": self._import,
|
||||||
"help": self._help,
|
"help": self._help,
|
||||||
"prune": self._prune,
|
"prune": self._prune,
|
||||||
"welcome": self._welcome,
|
"welcome": self._welcome,
|
||||||
|
@ -79,40 +79,40 @@ class Bot():
|
||||||
def send(self, message):
|
def send(self, message):
|
||||||
self.session.backend.handleMessage(self.session.user, self.name, message)
|
self.session.backend.handleMessage(self.session.user, self.name, message)
|
||||||
|
|
||||||
def __do_import(self, token):
|
# def __do_import(self, token):
|
||||||
# Google
|
# # Google
|
||||||
google = self.google.getContacts(token)
|
# google = self.google.getContacts(token)
|
||||||
self.send("%d buddies imported from google" % len(google))
|
# self.send("%d buddies imported from google" % len(google))
|
||||||
|
#
|
||||||
result = { }
|
# result = { }
|
||||||
for number, name in google.iteritems():
|
# for number, name in google.iteritems():
|
||||||
number = re.sub("[^0-9]", "", number)
|
# number = re.sub("[^0-9]", "", number)
|
||||||
number = number if number[0] == "0" else "+" + number
|
# number = number if number[0] == "0" else "+" + number
|
||||||
|
#
|
||||||
result[number] = { 'nick': name, 'state': 0 }
|
# result[number] = { 'nick': name, 'state': 0 }
|
||||||
|
#
|
||||||
# WhatsApp
|
# # WhatsApp
|
||||||
user = self.session.legacyName
|
# user = self.session.legacyName
|
||||||
password = self.session.password
|
# password = self.session.password
|
||||||
sync = WAContactsSyncRequest(user, password, result.keys())
|
# sync = WAContactsSyncRequest(user, password, result.keys())
|
||||||
whatsapp = sync.send()['c']
|
# whatsapp = sync.send()['c']
|
||||||
|
#
|
||||||
for w in whatsapp:
|
# for w in whatsapp:
|
||||||
result[w['p']]['state'] = w['w']
|
# result[w['p']]['state'] = w['w']
|
||||||
result[w['p']]['number'] = w['n']
|
# result[w['p']]['number'] = w['n']
|
||||||
|
#
|
||||||
self.send("%d buddies are using whatsapp" % len(filter(lambda w: w['w'], whatsapp)))
|
# self.send("%d buddies are using whatsapp" % len(filter(lambda w: w['w'], whatsapp)))
|
||||||
|
#
|
||||||
for r in result.values():
|
# for r in result.values():
|
||||||
if r['nick']:
|
# if r['nick']:
|
||||||
self.session.buddies.add(
|
# self.session.buddies.add(
|
||||||
number = r['number'],
|
# number = r['number'],
|
||||||
nick = r['nick'],
|
# nick = r['nick'],
|
||||||
groups = [u'Google'],
|
# groups = [u'Google'],
|
||||||
state = r['state']
|
# state = r['state']
|
||||||
)
|
# )
|
||||||
|
#
|
||||||
self.send("%d buddies imported" % len(whatsapp))
|
# self.send("%d buddies imported" % len(whatsapp))
|
||||||
|
|
||||||
def __get_token(self, filename, timeout = 30):
|
def __get_token(self, filename, timeout = 30):
|
||||||
file = open(filename, 'r')
|
file = open(filename, 'r')
|
||||||
|
@ -135,24 +135,24 @@ class Bot():
|
||||||
file.close()
|
file.close()
|
||||||
|
|
||||||
# commands
|
# commands
|
||||||
def _import(self, token = None):
|
# def _import(self, token = None):
|
||||||
if not token:
|
# if not token:
|
||||||
token_url = self.google.getTokenUrl("http://whatsapp.0l.de/auth.py")
|
# token_url = self.google.getTokenUrl("http://whatsapp.0l.de/auth.py")
|
||||||
auth_url = "http://whatsapp.0l.de/auth.py?number=%s&auth_url=%s" % (self.session.legacyName, urllib.quote(token_url))
|
# auth_url = "http://whatsapp.0l.de/auth.py?number=%s&auth_url=%s" % (self.session.legacyName, urllib.quote(token_url))
|
||||||
short_url = utils.shorten(auth_url)
|
# short_url = utils.shorten(auth_url)
|
||||||
self.send("please visit this url to auth: %s" % short_url)
|
# self.send("please visit this url to auth: %s" % short_url)
|
||||||
|
#
|
||||||
self.send("waiting for authorization...")
|
# self.send("waiting for authorization...")
|
||||||
token = self.__get_token(TOKEN_FILE)
|
# token = self.__get_token(TOKEN_FILE)
|
||||||
if token:
|
# if token:
|
||||||
self.send("got token: %s" % token)
|
# self.send("got token: %s" % token)
|
||||||
self.__do_import(token)
|
# self.__do_import(token)
|
||||||
self.session.updateRoster()
|
# self.session.updateRoster()
|
||||||
else:
|
# else:
|
||||||
self.send("timeout! please use \"\\import [token]\"")
|
# self.send("timeout! please use \"\\import [token]\"")
|
||||||
else:
|
# else:
|
||||||
self.__do_import(token)
|
# self.__do_import(token)
|
||||||
self.session.updateRoster()
|
# self.session.updateRoster()
|
||||||
|
|
||||||
def _sync(self):
|
def _sync(self):
|
||||||
user = self.session.legacyName
|
user = self.session.legacyName
|
||||||
|
|
Loading…
Reference in a new issue