Skip to main content

Whalesong is a python library to manage WebApps remotely. Currently WhatsappWeb is implemented

Documentation

http://whalesong.readthedocs.io/

Requirements

  • Python 3.6+

  • Geckodriver

  • Firefox 50+

Development requirements

  • node (only for development)

  • npm (only for development)

  • make (only for development)

Installation

$ pip install whalesong

Features

  • Non blocking driver. It can do more than one thing at same time.

  • Monitor feature. Python code could react to Javascript event.

  • Iterator feature. Large item list are passed to Python as async iterators.

  • Persistent Firefox profile.

  • Easy way to build new features.

  • AmpersandJS/BackboneJS models and collection monitor.

  • AmpersandJS/BackboneJS field monitor.

  • Monitor localStorage.

  • Take screenshots (page and css elements).

Whatsapp features

  • Monitor connection state.

  • Monitor QR changes.

  • Monitor stream state.

  • It’s able to refresh QR.

  • It’s able to take over session.

  • List chats.

  • List contacts.

  • List messages

  • Monitor new messages.

  • Monitor unread messages.

  • Monitor message acks.

  • Monitor new contacts.

  • Monitor new chats.

  • Send text messages.

  • Reply messages.

  • Send VCard messages.

  • Send Media (image/video/pdf) messages.

  • Send seen to chats.

  • Create groups

  • Manage groups (add/kick/promote/demote people)

Changelog

See documentation

TODO

  • Tests, tests, tests.

  • Documentation.

  • More examples.

  • Missing Whatsapp features.

  • Implement scriptlet for other WebApp (maybe Android Messages).

  • Drop Selenium and Geckodriver.

  • Create/Use a small footprint headless browser with async interface (like marionette).

  • Push results. Avoid continuous polling.

Getting started

Install library requirements

$ make requirements

Build Javascript scriplet

You have to rebuild scriptlet after any change if you want to use in Python code.

$ make build-js

Beautify code

You must to beautify code before make a pull request. Ugly code will not be accepted.

$ make beautify

Examples

Raw driver examples

State monitor

It monitors Stream state, Connection state and localStorage. It prints any change on them. It takes a page screenshot on each stream state change.

It tries to own WhatsappWeb session, it means that it will restore session if you open a new session in other browser.

On the other hand, if session is not started, it will renew QR automatically when it expires. It will save QR image each time it changes.

$ PYTHONPATH=.:$PYTHONPATH python3 examples/driver/statemonitor.py

Get contacts

It prints contact list.

$ PYTHONPATH=.:$PYTHONPATH python3 examples/driver/getcontacts.py

Get chats

It prints chat list.

$ PYTHONPATH=.:$PYTHONPATH python3 examples/driver/getchats.py

Get messages

It prints message list and monitors it. So, if new messages are received it will print them. It monitors message acknowledgments and prints them, as well.

$ PYTHONPATH=.:$PYTHONPATH python3 examples/driver/getmessages.py

Whatsapp driver examples

State monitor

It monitors Stream state, Connection state and localStorage. It prints any change on them. It takes a page screenshot on each stream state change.

It tries to own WhatsappWeb session, it means that it will restore session if you open a new session in other browser.

On the other hand, if session is not started, it will renew QR automatically when it expires. It will save QR image each time it changes.

$ PYTHONPATH=.:$PYTHONPATH python3 examples/statemonitor.py

Get contacts

It prints contact list.

$ PYTHONPATH=.:$PYTHONPATH python3 examples/getcontacts.py

Get chats

It prints chat list.

$ PYTHONPATH=.:$PYTHONPATH python3 examples/getchats.py

Get messages

It prints message list and monitors it. So, if new messages are received it will print them. It monitors message acknowledgments and prints them, as well.

It stores files and thumbnails from media messages.

$ PYTHONPATH=.:$PYTHONPATH python3 examples/getmessages.py

Minibot

Minibot implements 4 features:

Echo

When a contact sends /echo [text] it replies with [text].

Example
/echo Hello!
Contact

When a contact sends /contact [contactID] it replies with the contact in VCard format.

Example
/contact 495555555555
Download

When a contact sends /download [url] it replies with content pointed by URL (image, pdf, video).

Example
/download http://example.com/image.jpg
Send

When a contact sends /send [contactId] [text] it will send [text] to [contactId]. [contactId] must be a phone number with country prefix: 495555555555 where 49 is Germany prefix.

Example
/send 495555555555 Hello!
$ PYTHONPATH=.:$PYTHONPATH python3 examples/minibot.py

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

whalesong-0.5.2-py3-none-any.whl (70.6 kB view details)

Uploaded Python 3

File details

Details for the file whalesong-0.5.2-py3-none-any.whl.

File metadata

  • Download URL: whalesong-0.5.2-py3-none-any.whl
  • Upload date:
  • Size: 70.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/39.2.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.6.6

File hashes

Hashes for whalesong-0.5.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6929e797799889d2cba8345a3e90b8fba22a7199cf36e71b6fe4b694820147d8
MD5 8aabaef7205412546efe9f8787d59f28
BLAKE2b-256 66f97981ede46102658ad7effe4aff9de3df2c270552793904f7717710b06c13

See more details on using hashes here.

Release history Release notifications | RSS feed

0.9.0

1 file

0.8.4

1 file

0.8.2

1 file

0.8.1

1 file

0.8.0

1 file

0.7.2

1 file

0.7.1

1 file

0.7.0

1 file

0.6.0

1 file

0.5.3

1 file

This release

0.5.2 This release

1 file

0.5.1

1 file

0.5.0

1 file

0.4.4

1 file

0.4.3

1 file

0.4.2

1 file

0.4.1

1 file

0.4.0

1 file

0.3.0

1 file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page