Skip to content
This repository has been archived by the owner on Nov 2, 2023. It is now read-only.

Commit

Permalink
Merge pull request #14 from ngshiheng/add-scheduler
Browse files Browse the repository at this point in the history
Bot now uses configparser & schedule
  • Loading branch information
ngshiheng authored Oct 17, 2020
2 parents 5318ce7 + 050e8b3 commit 88ed3ec
Show file tree
Hide file tree
Showing 9 changed files with 160 additions and 95 deletions.
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ entrypoints = "==0.3"
mccabe = "==0.6.1"
selenium = "==3.141.0"
urllib3 = "==1.25.7"
schedule = "*"

[dev-packages]
autopep8 = "*"
Expand Down
10 changes: 9 additions & 1 deletion Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

79 changes: 37 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,60 +1,59 @@
# Six Percent :money_with_wings:
# Six Percent

This bot helps user to automatically purchase ASNB Fixed Price UT units. User shall proceed to make their own payment if there is a successful purchase attempt.
> _DISCLAIMER: Please use this at your own risk_
This bot helps user to automatically purchase ASNB Fixed Price UT units.

User shall proceed to make their own payment if there is a successful purchase attempt.

Currently, this bot supports up to 3 fixed price unit trust:

- ASM (Malaysia)
- ASM2 (Wawasan)
- ASM3 (1Malaysia)

Please **use this software at your own risk**!
Please read the disclaimer section.

_Note: As of Q3 2019, ASNB removed the need of solving CAPTCHA in order to purchase any ASNB Fixed Price UT_

## About myASNB Fixed Price Fund :moneybag:
## About myASNB Fixed Price Fund

ASNB is a subsidiary of “Permodalan Nasional Berhad” (PNB). It is a government-supported unit trust management company.

Amanah Saham are funds that are managed by Amanah Saham National Berhad (ASNB)

![alt text](https://i.imgur.com/LCB8Soo.jpg)

### Facts :newspaper:
### Facts

- If there is no units available, you will never be able to purchase new units or opening up a new account
- Fixed price (RM 1/unit) means there will be no price fluctuation. These funds can thus be regarded as saving accounts
- The dividend earned is not taxable
- No sales charge

For more details, visit the [myASNB Official Website](https://www.myasnb.com.my/)
For more details, visit [myASNB Official Website](https://www.myasnb.com.my/)

## Requirements & Dependencies

Please read carefully.

### Opening ASNB Account :closed_lock_with_key:
### Opening ASNB Account

- You need a ASNB account in order to start investing
- You can perform all the transactions (including opening an account) at any ASNB branches or agents

### Software :computer:
### Software

- Python 3.6+
- [pip](https://pip.pypa.io/en/stable/) package installer
- [pipenv](https://pypi.org/project/pipenv/)
- [chromedriver](https://chromedriver.chromium.org/downloads) based off your OS & Chrome version (Important!!!)
- [chromedriver](https://chromedriver.chromium.org/downloads) based on your OS & Chrome version

### User Configuration

### File configuration :document:
1. Update `config.ini` to edit your `chromedriver` path

- Config `config.ini` to edit your `chromedriver` path etc.
- Rename `users.json.example` to `users.json` and add/update the information accordingly. Change `"is_active": false` if you do not want to use the user
- Configure `funds.json`, set `"skip": true` if you do **NOT** want to buy that specific fund
2. Rename `users.example.json` to `users.json` and add/update the information accordingly. Change `"is_active": false` if you do **NOT** want to purchase units for that specific user

#### Installation (Ubuntu) :wrench:
3. Configure `funds.json`, set `"is_active": false` if you do **NOT** want to buy that specific fund

This project is tested and developed on Ubuntu 20.04.01 LTS. You can probably get this up and running on Windows or Mac with some minor tweaks.
### Installation (Ubuntu)

This project is tested and developed on `Ubuntu 20.04.01 LTS`. You can probably get this up and running on Windows or Mac with some minor tweaks

```bash
apt-get update && apt-get install -y --no-install-recommends python3 python3-virtualenv python3-pip chromium-chromedriver locales
Expand All @@ -64,21 +63,25 @@ locale-gen en_US.UTF-8

Run `./scripts/setup.sh` to install all the Python dependencies

Run `./scripts/run.sh` to start using the bot with scheduler (5 minutes)
### Installation (Windows)

> _Coming soon..._
### Installation (MacOS)

#### Installation (Windows)
> _Coming soon..._
_Coming soon..._
## How to use

#### Installation (MacOS)
1. Run `pipenv run python3 main.py`

_Coming soon..._
2. Job to purchase ASNB unit will start based on your configuration

## Setup & Run :nut_and_bolt:
3. Proceed to make your own payment if purchasing attempt is successful

To run only once, run `python3 main.py`
4. Repeat every 5 minutes (Able to modify in `config.ini` under `schedule_minutes`)

## Contributing :family:
## Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Expand All @@ -93,20 +96,12 @@ Pull requests are welcome. For major changes, please open an issue first to disc

## Disclaimer

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
> THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This software was designed to be used only for research purposes.

Uses are not recommended, and have never been evaluated.
This software comes with no warranties of any kind whatsoever,
and may not be useful for anything. Use it at your own risk!

This software comes with no warranties of any kind whatsoever, and may not be useful for anything. Use it at your own risk!

If these terms are not acceptable, you aren't allowed to use the code.
18 changes: 18 additions & 0 deletions config.ini
Original file line number Diff line number Diff line change
@@ -1,9 +1,27 @@
[chromedriver]
# REQUIRED
# File path to your `chromedriver`
# Download `chromedriver` at https://chromedriver.chromium.org/downloads
path = /usr/bin/chromedriver

[website]
# OPTIONAL
url = https://www.myasnb.com.my/uhsessionexpired

[browser]
# OPTIONAL
# Browser screen width and height
width = 1600
height = 900

[delay]
# OPTIONAL
# Randomize delay between clicks and submissions between `min_seconds` and `max_seconds`.
# I do not recommend setting `min_seconds` to anything less than 1 second
min_seconds = 1.00
max_seconds = 1.25

[schedule]
# OPTIONAL
# Attempt to purchase ASNB units every `schedule_minutes` minutes. Default run job every 5 minutes
schedule_minutes = 5
6 changes: 3 additions & 3 deletions funds.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
"name": "Amanah Saham Malaysia",
"alternate_name": "ASM",
"skip": false,
"is_active": true,
"elements": {
"id": "submit_buy_ASM",
"initial_investment_xpath": "//input[@id='submit_initial_invest_ASM']",
Expand All @@ -12,7 +12,7 @@
{
"name": "Amanah Saham Malaysia 2 - Wawasan",
"alternate_name": "ASW",
"skip": false,
"is_active": true,
"elements": {
"id": "submit_buy_ASW",
"initial_investment_xpath": "//input[@id='submit_initial_invest_ASW']",
Expand All @@ -22,7 +22,7 @@
{
"name": "Amanah Saham Malaysia 3",
"alternate_name": "AS1M",
"skip": false,
"is_active": true,
"elements": {
"id": "submit_buy_AS1M",
"initial_investment_xpath": "//input[@id='submit_initial_invest_AS1M']",
Expand Down
35 changes: 16 additions & 19 deletions lib/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import logging
import sys
import time
from configparser import ConfigParser
import random

from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
Expand All @@ -18,36 +18,33 @@ class SixPercent:
This is a bot which helps to automatically purchase ASNB Fixed Price UT units
"""

def __init__(self):

# Read user configurations from `config.ini` file
config = ConfigParser()
config.read('config.ini')

self.PATH_TO_CHROME_DRIVER = config.get('chromedriver', 'path')
self.ASNB_URL = config.get('website', 'url')
self.BROWSER_WIDTH = config.get('browser', 'width')
self.BROWSER_HEIGHT = config.get('browser', 'height')
def __init__(self, chrome_driver_path, url, browser_width=1600, browser_height=900, min_delay=1, max_delay=1):
self.url = url
self.chrome_driver_path = chrome_driver_path
self.browser_width = browser_width
self.browser_height = browser_height
self.min_delay = min_delay
self.max_delay = max_delay

# end def

def wait(self, delay=1):
def wait(self):
"""
Delay method, in seconds
Introduce a random delay between `min_delay` to `max_delay`
"""
time.sleep(delay)

time.sleep(random.uniform(self.min_delay, self.max_delay))
# end def

def launch_browser(self):
"""
Launches a chromedriver instance
"""

browser = webdriver.Chrome(self.PATH_TO_CHROME_DRIVER)
browser.get(self.ASNB_URL)
browser = webdriver.Chrome(self.chrome_driver_path)
browser.get(self.url)

return browser

# end def

def log_in(self, browser, asnb_username, asnb_password):
Expand All @@ -66,7 +63,7 @@ def log_in(self, browser, asnb_username, asnb_password):
browser.find_element_by_id("j_password_user").send_keys(Keys.ENTER)
logging.info('🔓 Successfully logged in')

browser.set_window_size(self.BROWSER_WIDTH, self.BROWSER_HEIGHT)
browser.set_window_size(self.browser_width, self.browser_height)
# end def

def log_out(self, browser):
Expand All @@ -91,7 +88,7 @@ def main_page(self, browser, investment_amount):
fund_data = json.load(f)

for i, fund in enumerate(fund_data):
if fund['skip']:
if not fund['is_active']:
continue
# end if

Expand Down
Loading

0 comments on commit 88ed3ec

Please sign in to comment.