Skip to content

Instantly share code, notes, and snippets.

@crearo
Created June 3, 2018 13:14
Show Gist options
  • Select an option

  • Save crearo/01a0d52b2922e4085bdf6d32d5b0d634 to your computer and use it in GitHub Desktop.

Select an option

Save crearo/01a0d52b2922e4085bdf6d32d5b0d634 to your computer and use it in GitHub Desktop.
Sends messages and calls a friend in a continuous loop to annoy them
#! /usr/bin/env python
'''
Created on June 3, 2018
@author: rish
This snippet sends messages or video calls a friend on Whatsapp.
This requires you to keep the Whatsapp chat page open for this to work.
'''
import sys, os, time, random
try:
sys.path.insert(0, os.path.join(os.environ['ANDROID_VIEW_CLIENT_HOME'], 'src'))
except:
pass
from com.dtmilano.android.viewclient import ViewClient, TextView, EditText
funny_strings = [
'this is an annoying sentence 1',
'this is an annoying sentence 2',
'this is an annoying sentence 3',
'this is an annoying sentence 4',
'this is an annoying sentence 5'
]
single_words = [
'human',
'person',
'friend'
]
def video_call(timeout):
vc.dump(window=-1)
ViewClient.sleep(0.1)
call_btn = vc.findViewWithContentDescriptionOrRaise(u'''Video call''')
if call_btn is None:
print 'unable to find the call button'
ViewClient.sleep(0.1)
return
call_btn.touch()
ViewClient.sleep(timeout)
vc.dump(window=-1)
ViewClient.sleep(0.1)
end_call_btn = vc.findViewById("com.whatsapp:id/end_call_btn")
if end_call_btn is None:
print 'looks like they cut the call before we could end it'
ViewClient.sleep(0.1)
return
end_call_btn.touch()
ViewClient.sleep(0.1)
def send_msg(msg):
vc.dump(window=-1)
ViewClient.sleep(0.1)
et = vc.findViewByIdOrRaise("com.whatsapp:id/entry")
et.touch()
et.type(msg)
ViewClient.sleep(0.1)
vc.dump(window=-1)
ViewClient.sleep(0.1)
send = vc.findViewByIdOrRaise("com.whatsapp:id/send")
send.touch()
if __name__ == '__main__':
device, serialno = ViewClient.connectToDeviceOrExit(verbose=True)
vc = ViewClient(device, serialno)
for i in range(0,100):
text ='#%d, Hello %s!\n%s' % (i, random.choice(single_words), random.choice(funny_strings))
send_msg(text)
print 'iteration [%d] %s' % (i, text)
if bool(random.getrandbits(1)):
video_call(3)
print 'fin'
@Rtfffd
Copy link
Copy Markdown

Rtfffd commented Jan 5, 2023

Thanks for ur guide

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment