forked from danielcardeenas/whatsapp-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
57 lines (44 loc) · 1.45 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
52
53
54
55
56
57
import sys, logging, config
from yowsup.layers.auth import AuthError
from yowsup.layers.axolotl.props import PROP_IDENTITY_AUTOTRUST
from yowsup.stacks import YowStackBuilder
from yowsup.layers import YowLayerEvent
from yowsup.layers.network import YowNetworkLayer
from app.layer import MacLayer
# Uncomment to log
#logging.basicConfig(level=logging.DEBUG)
# Config
credentials = (config.credentials['phone'], config.credentials['password'])
encryption = True
class MacStack(object):
def __init__(self):
builder = YowStackBuilder()
self.stack = builder\
.pushDefaultLayers(encryption)\
.push(MacLayer)\
.build()
self.stack.setCredentials(credentials)
self.stack.setProp(MacLayer.PROP_CONTACTS, list(config.contacts.keys()))
self.stack.setProp(PROP_IDENTITY_AUTOTRUST, True)
def start(self):
print("[Whatsapp] Mac started\n")
self.stack.broadcastEvent(YowLayerEvent(YowNetworkLayer.EVENT_STATE_CONNECT))
try:
self.stack.loop(timeout=0.5, discrete=0.5)
except AuthError as e:
print("Auth Error, reason %s" % e)
except KeyboardInterrupt:
print("\nYowsdown")
sys.exit(0)
def run_infinite():
while True:
try:
c = MacStack()
c.start()
except:
pass
else:
break
if __name__ == "__main__":
c = MacStack()
c.start()