Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Koen van der Veen
whatsapp
Commits
b9c52313
Commit
b9c52313
authored
3 years ago
by
Alp Deniz Ogut
Browse files
Options
Download
Email Patches
Plain Diff
Init daemon mode
parent
2a6230b6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
whatsapp/plugin.py
+26
-8
whatsapp/plugin.py
whatsapp/web_client/client.py
+6
-1
whatsapp/web_client/client.py
with
32 additions
and
9 deletions
+32
-9
whatsapp/plugin.py
+
26
-
8
View file @
b9c52313
...
...
@@ -41,13 +41,20 @@ class WhatsappPlugin(PluginBase):
return
try
:
self
.
get_me_profile_picture
(
)
self
.
collect_picture
(
self
.
me_id
)
self
.
collect_chat_messages
()
self
.
collect_pictures
()
except
KeyboardInterrupt
:
print
(
"Keyboard interrupt"
)
except
Exception
as
e
:
print
(
"Error during import:"
,
e
)
finally
:
print
(
"[+] Whatsapp plugin import complete"
)
try
:
self
.
setup_daemon_mode
()
except
Exception
as
e
:
print
(
"Error while listening whatsapp"
,
e
)
finally
:
self
.
socket
.
close
()
print
(
"[+] Whatsapp plugin run complete"
)
...
...
@@ -86,15 +93,25 @@ class WhatsappPlugin(PluginBase):
self
.
store_credentials
()
print
(
"[+] Saved session"
)
def
setup_daemon_mode
(
self
):
self
.
socket
.
keepAlive
()
self
.
set_run_status
(
"daemon"
)
self
.
setup_run_status_listener
()
def
setup_run_status_listener
(
self
):
# plugin run listener for daemons
while
True
:
sleep
(
1
)
run
=
self
.
client
.
get
(
self
.
pluginRun
.
id
)
if
run
.
status
==
"aborted"
:
print
(
f
"
{
SERVICE_NAME
}
plugin is being aborted"
)
return
def
wait_for
(
self
,
ctr
):
while
self
.
counter
[
ctr
][
0
]
<
self
.
counter
[
ctr
][
1
]:
sleep
(
0.
2
)
sleep
(
0.
5
)
print
(
"GOT ALL"
,
ctr
.
upper
())
def
get_me_profile_picture
(
self
):
self
.
socket
.
get_profile_picture
(
self
.
me_id
,
self
.
process_profile_picture_response
)
self
.
counter
[
GOT_PICS
][
1
]
+=
1
def
collect_picture
(
self
,
jid
):
print
(
f
"
\t
Requesting profile picture of
{
jid
}
"
,
flush
=
True
)
self
.
socket
.
get_profile_picture
(
jid
,
self
.
process_profile_picture_response
)
...
...
@@ -106,7 +123,7 @@ class WhatsappPlugin(PluginBase):
for
contact
in
self
.
contacts
.
values
():
# request if not already fetched
if
len
(
contact
.
profilePicture
)
==
0
:
self
.
collect_
profile_
picture
(
contact
.
externalId
)
self
.
collect_picture
(
contact
.
externalId
)
sleep
(
0.5
)
self
.
wait_for
(
GOT_PICS
)
...
...
@@ -168,6 +185,7 @@ class WhatsappPlugin(PluginBase):
def
handle_contacts
(
self
,
response_data
):
accounts
=
[]
# existing_account_ids = helpers.get_external_ids(type='Account')
_
,
_
,
contacts
=
response_data
for
_
,
contact
,
_
in
contacts
:
account
=
helpers
.
contact_to_account
(
contact
)
...
...
@@ -248,7 +266,7 @@ class WhatsappPlugin(PluginBase):
photo
.
externalId
=
jid
self
.
client
.
create_photo
(
photo
)
if
jid
!=
self
.
me_id
:
if
jid
in
self
.
chats
:
# set conversation (either group or contact) picture
self
.
chats
[
jid
].
add_edge
(
'photo'
,
photo
)
self
.
chats
[
jid
].
update
(
self
.
client
)
...
...
This diff is collapsed.
Click to expand it.
whatsapp/web_client/client.py
+
6
-
1
View file @
b9c52313
...
...
@@ -6,7 +6,7 @@ sys.dont_write_bytecode = True;
import
os
import
base64
;
from
threading
import
Thread
from
threading
import
Thread
,
Timer
import
json
import
io
from
time
import
sleep
;
...
...
@@ -133,6 +133,11 @@ class WhatsAppWebClient:
except
Exception
as
e
:
print
(
"Error while handling incoming message"
,
traceback
.
format_exc
());
def
keepAlive
(
self
):
if
self
.
activeWs
is
not
None
:
self
.
activeWs
.
send
(
"?,,"
)
Timer
(
20.0
,
self
.
keepAlive
).
start
()
def
handle_init_response
(
self
,
message_content
,
pend
):
if
not
self
.
logged_in
:
try
:
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment