Skip to content

Commit

Permalink
PR bntzio#1 Basic Restructure & Authentication handling, Message Form…
Browse files Browse the repository at this point in the history
…atting, And Basic Sending
  • Loading branch information
SN3-K committed May 30, 2020
1 parent f8d64d8 commit 7b8ab6a
Show file tree
Hide file tree
Showing 7 changed files with 404 additions and 1 deletion.
9 changes: 9 additions & 0 deletions conf.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"default_xpath_text_area": "//footer/div/div[2]/div/div[2]",
"default_xpath_authenticated": "//*[text() = 'Keep your phone connected']",
"default_xpath_searchbar":"//div[@id='side']/div/div/label/div/div[2]",
"default_xpath_send_button":"/html/body/div[1]/div/div/div[4]/div/footer/div[1]/div[3]/button",
"default_xpath_target_user":"//span[contains(.,'%s')]",
"control_user": {"user":"Enrique","currency_format":"$","bank_account":"4531-2321-3421-3421"},
"kill_on_auth":"0"
}
90 changes: 90 additions & 0 deletions guide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
## Glossary

whatsapp_debt_framework :
Arguments
- production - Optional | Default : True
- message - Required - Raises ValueError if None example : Invalid Message Can Not Be None, Empty, or Null!
- debug - Optional - Default True - Turns Verbose on
- debug_data - Optional - Default False - Switches from database mode to importing json data from debtor_data.json

Public methods:
- self.production -
- self.url_bin -
- self.notice -
- self.msg_count -

Private methods:
- self.queue -
- self._kill_on_auth -
- self._default_xpath_text_area -
- self._default_xpath_authenticated -
- self._callbacks -
- self._control_user -

Public Functions:
- self.collect -
Arguments
-
Returns
-

- self.authenticate
Arguments
- None

Returns
-

- self.connect - # Depreciated
Arguments
-None

Returns
-

- self.get_message -
Arguments
-target_data - required list(target,amount) Strict
-message - Optional -Type: Str - Has preset text if left default - Default : 'default.upper()'

Returns
-

Private Functions:
- self._logit -
Arguments
- log_text - Required - Type: Str
- verbose - Optional - Default False - Print or just Return logs (T/F) Overridden by self.debug
Returns
-
- self._set_chrome_options - Sets browser to headless and screen size to 1920x1080 Mac OSX headers
Arguments
- None
Returns
-
## About
Payment Gateways:
- N/A


<br/>

## Usage

Using the whats app debt framework is very straight forward.

example :

TARGETS = {'name': amount} # yep it is that easy, format the debtor and the value here and run!
whatsapp_debt_framework().start(targets=TARGETS)

name = str
amount = int

calling start() will automatically open an instance of chrome and request you scan the qr code for your whatsapp on your phone.
Once authenticated the framework will continue through your dictionary of 'TARGETS' and send a message to each debtor about the amount using a default message, if you want to personalize what message goes into the chat windows, refer to the following example:


TARGETS = {'name': amount} # yep it is that easy, format the debtor and the value here and run!
message = '{name} Don't forget you have an outstanding balance with Apple for {amount}'
whatsapp_debt_framework().start(targets=TARGETS,message=message)
96 changes: 96 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,43 @@
# WhatsApp Debt (in progress)

Stable Releases:

OS:

Ubuntu 18.04 LTS [TESTED] : Working no Issues

Else:

Not Tested


[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)

> Automating the tedious task of collecting debts 💰
### Todos
BASE

- [ ] Add CLI args to turn on/off production mode
- [ ] Add cronfile to specify the time the bot will run
- [ ] Create a json file to save debt info
- [ ] Add deployment instructions
- [ ] Update readme
- [ ] Add GIF demo
- [ ] Add GIF Demos for conf.json with Screenshots and guide on how to use selenium ide to fetch xpath fields.
- [x] Add MIT license
- [ ] Depreciate Connect until Persistence issues are fixed
- [ ] Scope, Rename, Finish Alpha Collect()
- [x] Complete Alpha Stages of Authenticate()
- [x] Temp Depreciated connect
- [ ] Create private function (in init) that loads configs
- [x] Create conf.json file
- [ ] Restructure application to a proper file hierarchy

EXTENDED

[ ] Resolve issues with solving the QR via image (driver.element.screenshot(filename='name.png')) when displaying on local machine or web, can not verify
[ ] Find Solution for persistent Headless Login

### Roadmap

Expand All @@ -21,3 +46,74 @@
- [ ] Create app & database to dynamically add or remove people from debt

**Feel free to collaborate!**
For information about Issues see issue_guide.md



### For Usage Guides Check guide.md!
### For Issue Guide check out issue_guide.md

This platform was built with the idea of making collection of automated payments through whats app an easy process. A Final version of this platform should be applicable to facilitate P2P Loans with Ease. This system should also be able to be adapted for instance for monthly payments, if a store were to collect 29.99 every 31 days, this can be a general use case for this type of platform.




### Installation & Deployment


Step 1: Download the source code to your local working directory

Step 2: cd into the directory and create a virtual environemnt called wdf

Step 3: activate your virtual env

Step 4: install the requirements with pip install -r requirements.txt

Step 5: Navigate to conf.json Replace control_user information with relevant information

Step 6: Navigate to unit_test.py and Complete the TARGET information

Step 7: Navigate to your console and run python3 unit_test.py

Your done!




### Notes

An example of using the platform in it's default form, is in unit_test.py, the way this framework was built is to do all of the heavy lifting for you, feed the target, amount, and authenticate it will handle the rest for you.


An example of using a Scheduler with this type of application to run every x time frame and so on, is in scheduler.py, A more advanced tutorial will be made available in latter versions.


###Useful Information


conf.json is per say the configuration file for this framework, you will notice these elements at the time of writing :



{
"default_xpath_text_area": "//footer/div/div[2]/div/div[2]",
"default_xpath_authenticated": "//*[text() = 'Keep your phone connected']",
"default_xpath_searchbar":"//div[@id='side']/div/div/label/div/div[2]",
"default_xpath_send_button":"//div[3]/button/span",
"default_xpath_target_user":"//span[contains(.,'%s')]",
"control_user": {"user":"Enrique","currency_format":"$","bank_account":"4531-2321-3421-3421"},
"kill_on_auth":"0"
}


The First element default_xpath_text_area Defines : The chat space to use the send_keys() functions to send a message in whatsapp web (authenticated)

The Second Element default_xpath_authenticated Defines: A point of the whatsapp website that undeniably proves you are authenticated e.g the search bar.

The Third Element default_xpath_searchbar Defines: The Search bar behind whatsapp web (authenticated)

The Fourth Element default_xpath_send_button Defines: The send a message button in a whatsapp chat

The Fifth Element default_xpath_target_user Defines : The xpath used to identify a web element with the text of the target user for per say the chat window we need to click

The Sixth Element control_user Defines: Default control user settings that defines who the debt collector is (user), The currency format ($), and the bank account associated (will be changed later for other payment methods)
18 changes: 18 additions & 0 deletions scheduler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from whatsapp_framework import whatsapp_debt_framework
import schedule
import time

# pip install scheduler

TARGETS = {'GAGAN-DEV': 10} # yep it is that easy, format the debtor and the value here and run!


def job():
return whatsapp_debt_framework()._logit(f'Running Job...'),whatsapp_debt_framework().start(targets=TARGETS)

schedule.every().day.at('15:16').do(job) #24hr format

whatsapp_debt_framework()._logit(f'Waiting for Scheduled Jobs to Trigger...')
while True:
schedule.run_pending()
time.sleep(1) # reduce CPU load with a wait
4 changes: 3 additions & 1 deletion script.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# DEPRECIATED!
from urllib.parse import quote
from time import sleep
from pyperclip import copy
Expand All @@ -24,13 +25,14 @@ def get_message(target):
chrome_options.add_argument(
'user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2227.1 Safari/537.36'
)
browser = webdriver.Chrome(chrome_options=chrome_options)
browser = webdriver.Chrome(chrome_options=chrome_options,executable_path='/usr/local/bin/chromedriver')
browser.get('https://web.whatsapp.com')
while SCANNED is False:
image = browser.find_element_by_tag_name('img')
image_src = image.get_attribute('src')
encoded = quote(image_src, safe='')
url = HOST + '/' + encoded
print(url)
copy(url)
print('\nLink copied to your clipboard, you got 20 seconds to visit it and scan your QR code.')
print('Waiting QR Scanning...')
Expand Down
7 changes: 7 additions & 0 deletions unit_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from whatsapp_framework import whatsapp_debt_framework


# pip install scheduler

TARGETS = {'GAGAN-DEV': 10} # yep it is that easy, format the debtor and the value here and run!
whatsapp_debt_framework().start(targets=TARGETS)
Loading

0 comments on commit 7b8ab6a

Please sign in to comment.