alfred82santa / whalesong

Whalesong is an asyncio python library to manage WebApps remotely. Currently WhatsappWeb is implemented
https://whalesong.readthedocs.io
MIT License
51 stars 19 forks source link
asyncio puppeteer python selenium webapp whatsapp whatsappweb

.. |badge-python-versions| image:: https://img.shields.io/pypi/pyversions/whalesong.svg :alt: Python versions

.. |badge-version| image:: https://img.shields.io/pypi/v/whalesong.svg :alt: Last version :target: https://pypi.org/project/whalesong/

.. |badge-license| image:: https://img.shields.io/pypi/l/whalesong.svg :alt: License

.. |badge-status| image:: https://img.shields.io/pypi/status/whalesong.svg :alt: Status

|badge-status| |badge-license| |badge-version| |badge-python-versions|

.. warning::

NEW VERSION 0.7.0

With new version some new requirements have been defined and some API change have been committed.

Version 0.7.0 introduces new driver for Chromium browser. It has required some changes on base driver's API. It should not affect anyone. But be aware.

.. warning::

NEW VERSION 0.7.0

Stream model now uses enumerations. It means that if you check stream states you must be aware that they are not a string anymore, now they are enumerations. Look at :class:documentation <whalesong.managers.stream.Stream>.

========= Whalesong

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


Documentation

http://whalesong.readthedocs.io/


Binary Requirements

............. Using Firefox .............

.............. Using Chromium ..............

........................ Development requirements ........................


Installation

Starting with version 0.7.0 Whalesong introduces new browsers backends <browser_backends>_. It means you must decide which browser backend you want to use. So, depending on it:

.. tip::

You could install both with no problems.

............. Using Firefox .............

.. code-block:: bash

$ pip3 install whalesong[firefox]

.. _using_chromium:

.............. Using Chronium ..............

.. code-block:: bash

$ pip3 install whalesong[chromium]

If you choose Chromium backend, you should execute this after installation:

.. code-block:: bash

$ pyppeteer-install

It will download a patched Chromium distribution needed for that backend.


Features

................. Whatsapp features .................


Changelog

See documentation <https://whalesong.readthedocs.io/en/latest/changelog.html>_


TODO

.. _browser_backends:


Browser backends

Whalesong use a browser backend in order to execute a WebApp (currently only WhatsAppWeb). All backends have an interface to manage webviews and that is what Whalesong use to manage applications. That interface change depending on browser, but there is a standard interface called WebDriver <https://developer.mozilla.org/en-US/docs/Web/WebDriver>. Firsts Whalesong versions used to use a Selenium <https://www.seleniumhq.org/> library in order to communicate with Firefox browser. This backend is the default one for now, but it will be deprecated in next versions and removed in version 1.0.

............... Firefox backend ...............

It was the first backend developed. It uses Selenium <https://www.seleniumhq.org/> library and Geckodriver <https://firefox-source-docs.mozilla.org/testing/geckodriver/geckodriver/> to communicate with Firefox process. It is the most tested (the most, but not well).

Pros

Contras

.. note::

**There is only one way for the Firefox backend to survive:**

Drop Selenium, drop Geckodriver, implement Marionette protocol directly and implement a notification
system (I'm not sure it is possible in Marionette, currently).

How to use

Currently Firefox backend is the default one. But it will change on next versions. So, in order to ensure you use Firefox backend you must instantiate Whalesong with proper driver.

.. code-block:: python3

from whalesong import Whalesong from whalesong.driver_firefox import WhalesongDriver

driver = WhalesongDriver(profile='/path/to/your/firefox/profile') whaleapp = Whalesong(driver=driver)

................ Chromium backend ................

It is the new one. It is implemented using Pyppetter <https://github.com/miyakogi/pyppeteer> which is inspired on Puppetter <https://pptr.dev/> (a node library to control Chromium headless, mainly, for testing). It uses Devtools protocol <https://chromedevtools.github.io/devtools-protocol/>_ in order to communicate with the browser. It is an asynchronous protocol over websocket.

Pros

Contras

How to use

In order to use Chromium backend you must inject Chromium driver to Whalesong service constructor.

.. code-block:: python3

from whalesong import Whalesong from whalesong.driver_chromium import WhalesongDriver

driver = WhalesongDriver(profile='/path/to/your/chromium/profile') whaleapp = Whalesong(driver=driver)

.............. Other backends ..............

No, there are no other backends. But I'm thinking about other possibilities:

Of course, any contribution will be welcome (so much).


Getting started

............................ Install library requirements ............................

.. code-block:: bash

$ make requirements

......................... Build Javascript scriplet .........................

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

.. code-block:: bash

$ make build-js

............. Beautify code .............

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

.. code-block:: bash

$ make beautify

Examples

See documentation <https://whalesong.readthedocs.io/en/latest/examples.html>_


Related projects

............ whalesong-js ............

Port of Whalesong to Node.js.

Author: @jabolina <https://github.com/jabolina>_

Repository: https://github.com/jabolina/whalesong-js


Legal

This code is in no way affiliated with, authorized, maintained, sponsored or endorsed by WhatsApp or any of its affiliates or subsidiaries. This is an independent and unofficial software. Use at your own risk.