Skip to content
This repository has been archived by the owner on Mar 29, 2021. It is now read-only.

Commit

Permalink
Merge pull request #25 from aahnik/dev
Browse files Browse the repository at this point in the history
Release  0.5.0.beta
  • Loading branch information
aahnik authored Sep 25, 2020
2 parents 7a9aa1e + 672b15b commit cb31ba4
Show file tree
Hide file tree
Showing 22 changed files with 368 additions and 337 deletions.
13 changes: 9 additions & 4 deletions .github/var
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
whatsapp_web_url: https://web.whatsapp.com/
mBox: /html/body/div/div/div/div[4]/div/footer/div[1]/div[2]/div/div[2]
mainScreenLoaded: ._3FRCZ
searchSelector: .cBxw- > div:nth-child(2)
whatsapp_web_url: 'https://web.whatsapp.com/'
messageBox: '/html/body/div/div/div/div[4]/div/footer/div[1]/div[2]/div/div[2]'
mainScreenLoaded: '._3FRCZ'
searchSelector: '.cBxw- > div:nth-child(2)'
person: '//*[@title="name"]'
attach: '//span[@data-icon="clip"]'
send: '//span[@data-icon="send"]'
media: '//input[@accept="image/*,video/mp4,video/3gpp,video/quicktime"][@type="file"]'
file: '//input[@accept="*"]'
# Aahnik 2020
2 changes: 1 addition & 1 deletion .github/ver
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4
5
36 changes: 12 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,30 @@
Wondering how to send WhatsApp messages using Python using only few lines of code? You have come to the right place!

[![Tests](https://img.shields.io/badge/tests-passing-green)](https://aahnik.github.io/wappdriver/docs/Tests.html)
[![Maintenance](https://img.shields.io/maintenance/yes/2020)](https://github.com/aahnik/wappdriver/graphs/commit-activity)
[![GitHub Release](https://img.shields.io/github/v/release/aahnik/wappdriver)](https://github.com/aahnik/wappdriver/releases)
[![CodeFactor](https://www.codefactor.io/repository/github/aahnik/wappdriver/badge)](https://www.codefactor.io/repository/github/aahnik/wappdriver)


_`wappdriver` enables you to send WhatsApp messages programmatically, using only 3 lines of code._

**A python package that helps you automate sending messages through WhatsApp Web 😎**

[![Maintenance](https://img.shields.io/maintenance/yes/2020)](https://github.com/aahnik/wappdriver/graphs/commit-activity)
[![GitHub Release](https://img.shields.io/github/v/release/aahnik/wappdriver)](https://github.com/aahnik/wappdriver/releases)
[![CodeFactor](https://www.codefactor.io/repository/github/aahnik/wappdriver/badge)](https://www.codefactor.io/repository/github/aahnik/wappdriver)

### *🌟🌟 New*
WappDriver now supports sending **images** , **videos**, **documents** and other file types... *[learn usage](https://aahnik.github.io/wappdriver/docs/Documentation.html)*


### It's very simple to use

```python
import wappdriver as wa
bot = wa.WappDriver()
bot.send_message(to='aahnik',msg='Hi ! sent by a bot :-p ')
# the recipients name must be saved in your contacts ...

```
![wapp_driver_scrnsht](https://user-images.githubusercontent.com/66209958/90502857-2879a600-e16c-11ea-8f7f-7bbf2a993a13.png)
![using wappdriver](docs/images/wappdriver.png).

### How to install ??

```
pip3 install wappdriver
pip install wappdriver
```
For Mac and Linux, you may need to use `pip3`.

[PyPI](https://pypi.org/project/wappdriver/)

[![MIT LICENSE](https://img.shields.io/pypi/l/ansicolortags.svg)](/LICENSE)
Expand All @@ -42,8 +39,6 @@ So **make sure to close any chrome tab which has WhatsApp Web open**. Not doing
- Your phone which is having that WhatsApp account, must stay connected to internet for WhatsApp Web to work




### Requirements

[![made-with-python](https://img.shields.io/badge/Made%20with-Python-1f425f.svg)](https://www.python.org/)
Expand All @@ -58,24 +53,17 @@ I recommend to use the latest version of both, for the best performance.

### Documentation

[Read](https://aahnik.github.io/wappdriver/docs/Documentation.html) the full Documentation.

### Tests

[Learn more](https://aahnik.github.io/wappdriver/docs/Tests.html) about testing.

[Read](https://aahnik.github.io/wappdriver/docs/Documentation.html) the full Documentation to know about all the features.


### Want to contribute ?

Please look at [Code of Conduct](https://github.com/aahnik/wappdriver/blob/master/.github/CODE_OF_CONDUCT.md#contributor-covenant-code-of-conduct) and [Contributing Guidelines](https://github.com/aahnik/wappdriver/blob/master/.github/CONTRIBUTING.md#how-to-contribute-to-wappdriver-)

Please read the explanation of the detailed working of `wappdriver` from the [Developer's Guide.](https://aahnik.github.io/wappdriver/docs/For_Developers.html)



### Special Thanks to @VISWESWARAN1998
I learned a lot from his [repo](https://github.com/aahnik/Simple-Yet-Hackable-WhatsApp-api) and had initially started working on it. In future, due to certain requirements, I created a seperate repo, with a different working all together.

### Help

For _help_ you can **email me** at [[email protected]](mailto:[email protected]) or **chat** on [Telegram](https://t.me/AahnikDaw).You can expect a reply within 48 hours.
Expand Down
35 changes: 35 additions & 0 deletions docs/Documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,41 @@
This is a detailed documentation of the functioning of `wappdriver`. [README](https://aahnik.github.io/wappdriver) for introduction.

- [Documentation](#documentation)
- [First time Setup](#first-time-setup)
- [Sending Images, Videos, Documents and other Files](#sending-images-videos-documents-and-other-files)
- [Sending Multiple Files Together](#sending-multiple-files-together)
- [Sending Messages with Files](#sending-messages-with-files)

## First time Setup

There is no hassle in setting up `wappdriver`.
>Make sure you have matching versions of Chrome and Chrome Driver.
After you `pip install wappdriver`, you can directly run your code.
- You will be prompted to enter the installation path of Chrome Driver Executable (only once). Just copy and paste the correct path there.
- When you load WhatsApp for the first time, you have to scan the QR Code that will be displayed on your computer from your phone, to login into WhatsApp Web



## Sending Images, Videos, Documents and other Files

With `wappdriver` its easy to do all these. Simply pass the path of the image or video or document file to the `send` method. You must use absoulte file paths.
You can send any file type that WhatsApp supports.
> WhatsApp does not support files over 16 MB
![sending an image](images/sending_media.png)

## Sending Multiple Files Together

You can easily pass as many arguments to `send` method of `WhatsApp` class you wish.
**Just remember that the first argument must be the name of the recipient.**

![sending multiple files](images/sending_multiple_files.png)


## Sending Messages with Files

Hmm! `wappdriver` is extremely smart. It can detect whether a string is a message or a file path. So you can do this as shown below. Dont hesitate to use a multiline line string for a long message.

![files and messages](images/files_and_messages.png)

The messages will be send in exactly that order.
39 changes: 0 additions & 39 deletions docs/Tests.md

This file was deleted.

Binary file added docs/images/files_and_messages.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/sending_media.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/sending_multiple_files.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/wappdriver.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 2 additions & 11 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,10 @@ certifi==2020.6.20
chardet==3.0.4
idna==2.10
pycodestyle==2.6.0
PyYAML==5.3.1
requests==2.24.0
selenium==3.141.0
toml==0.10.1
urllib3==1.25.10
autopep8==1.5.4
certifi==2020.6.20
chardet==3.0.4
idna==2.10
pycodestyle==2.6.0
pyfiglet==0.8.post1
PyYAML==5.3.1
requests==2.24.0
selenium==3.141.0
toml==0.10.1
urllib3==1.25.10
tqdm==4.49.0
urllib3==1.25.10
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/aahnik/wappdriver",
install_requires=['selenium', 'pyyaml', 'requests', 'pyfiglet','pytest'],
install_requires=['selenium', 'pyyaml', 'requests', 'pyfiglet','tqdm'],
include_package_data=True,
zip_safe=False,
entry_points={
Expand Down
8 changes: 5 additions & 3 deletions wappdriver/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
__version__ = "0.3.2"
__version__ = "0.5.0.beta"

from .driver import WappDriver
# from .context import Wapp
from .data.local import set_chrome_driver_path, update_vars

from .error import handle_errors
from .driver import WappDriver
from .whatsapp import category,WhatsApp
# AAHNIK 2020
15 changes: 12 additions & 3 deletions wappdriver/command_line.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
from . import __version__
import argparse
from pyfiglet import Figlet

try:
from pyfiglet import Figlet
except Exception:
print('''Could not find pyfiglet
Run
pip install pyfiglet
''')


def main():
parser = argparse.ArgumentParser()
args = parser.parse_args()
print(f'wappdriver: {__version__}')
print(f'''
wappdriver: {__version__}
Command Line App is not availaible.
Please Update wappdriver
''')
f = Figlet(font='big')
print(f.renderText('wappdriver'))



if __name__ == "__main__":
main()
51 changes: 51 additions & 0 deletions wappdriver/data/data_error.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
'''
The errors that occur during Data Handling are handled by the decorators defined in this module
'''


def handle_connection(func):
def wrapper_func(*args):
try:
return func()
except Exception as err:
print(f'''
-----------------------------------
😞
Could not fetch data from Internet.
Please check your connection
{err}
For help visit
https://aahnik.github.io/wappdriver/docs/help.html
-----------------------------------
''')
quit()
return wrapper_func


def handle_dependancy(func):
def wrapper_func(*args):
try:
return func()
except Exception as err:
print(f'''
-----------------------------------
😞
Dependancies Missing
{err}
Please run
pip install pyyaml requests
And then try again
For help visit
https://aahnik.github.io/wappdriver/docs/help.html
-----------------------------------
''')
quit()
return wrapper_func
21 changes: 14 additions & 7 deletions wappdriver/data/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@
---
Updates can be performed manually by calling `update_vars()`
'''

from .. import __version__
from datetime import datetime
from .data_error import handle_dependancy
from . import remote
import os
import yaml
from datetime import datetime
from .. import __version__


@handle_dependancy
def yml():
import yaml
return yaml


wapp_dir = os.path.expanduser('~/.wappdriver')
Expand All @@ -21,7 +26,8 @@

version_file = os.path.join(wapp_dir, 'ver.txt')

sessions_dir = os.path.join(wapp_dir,'sessions')
sessions_dir = os.path.join(wapp_dir, 'sessions')


def set_chrome_driver_path(path=''):
'''
Expand Down Expand Up @@ -80,7 +86,7 @@ def get_local_vars():
Returns the vars dictionary
'''
with open(var_file, 'r') as f:
return yaml.full_load(f)
return yml().full_load(f)


def set_local_ver(ver):
Expand Down Expand Up @@ -123,7 +129,8 @@ def update_vars():
return True

except Exception as e:
print(f'Could not update data from Internet. Check your internet connection \n {e}')
print(
f'Could not update data from Internet. Check your internet connection \n {e}')


def ensure():
Expand Down
19 changes: 16 additions & 3 deletions wappdriver/data/remote.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,35 @@
'''This module remote.py provides access to remote. It fetches latest data from the internet'''

import requests
from .data_error import handle_connection, handle_dependancy


@handle_dependancy
def rqst():
import requests
return requests


prefix = 'https://raw.githubusercontent.com/aahnik/wappdriver/main/.github/'

version_url = f'{prefix}ver'
var_url = f'{prefix}var'


@handle_connection
def version():
'''
Returns remote version
'''
return float(requests.get(url=version_url).text)
ver = float(rqst().get(url=version_url).text)
return ver


@handle_connection
def fetch_vars():
'''
Returns the content of remote vars as a string
'''
return requests.get(url=var_url).text
dynamic_vars = rqst().get(url=var_url).text
return dynamic_vars


Loading

0 comments on commit cb31ba4

Please sign in to comment.