forked from onvotar-bot/onvotar-whatsapp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
51 lines (37 loc) · 1.2 KB
/
run.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import sys
from yowsup.stacks import YowStackBuilder
from layer import EchoLayer
from yowsup.layers.auth import AuthError
from yowsup.layers import YowLayerEvent
from yowsup.layers.network import YowNetworkLayer
CREDENTIALS = ("yowsup_id", "yowsup_password")
class YowsupEchoStack(object):
def __init__(self, credentials, encryptionEnabled=True):
stackBuilder = YowStackBuilder()
self.stack = stackBuilder\
.pushDefaultLayers(encryptionEnabled)\
.push(EchoLayer)\
.build()
self.stack.setCredentials(credentials)
self.stack.broadcastEvent(
YowLayerEvent(YowNetworkLayer.EVENT_STATE_CONNECT))
def start(self):
try:
print("\nIniciant loop...")
self.stack.loop()
except AuthError as e:
print("Authentication Error: %s" % e.message)
def initialize():
stack = YowsupEchoStack(CREDENTIALS)
run(stack)
def run(stack):
try:
stack.start()
except KeyboardInterrupt:
print("\nHasta nunqui!")
sys.exit(0)
except:
print("\nExcepcio descontrolada, tornem a executar")
run(stack)
if __name__ == '__main__':
initialize()