GitHub PyNanaco
--You can use selenium to access the nanaco web page to log in / log out, charge your credit card, and set / cancel your credit card. ――You can charge up to 50,000 yen with one command.
--Since you can charge 50,000 yen with one operation, it is easier than operating the web screen --The work of setting / canceling credit cards for multiple nanaco cards can be described in just a few lines. --If you link it with cron or scheduler separately, you can charge nanaco and change credit card settings by batch processing.
I haven't registered with PyPI, so please use Git.
pip install git+https://github.com/sawadyrr5/PyNanaco
Selenium should be installed at the time of installation, but if not, please install with pip install selenium
.
You need to put chromedriver.exe
in the same location as core.py
.
Click here to get it.
chrome webdriver
login(nanaco_number, card_number, password)
Log in to the nanaco menu screen. Enter * card_number * to log in with the number on the card, * password * to log in with your mobile member password. (If you enter both, * card_number * has priority) If you prepare nanaco information in dict type in advance, you can log in like this.
python
my_nanaco = dict(
nanaco_number='xxxxxxxxxxxxxxxx',
card_number='yyyyyyy'
)
nanaco = PyNanaco()
nanaco.login(**my_nanaco)
login_credit_charge(credit_charge_password)
The screen will change to the credit charge screen. If the credit charge is already registered, the registered card number will be returned. (A string such as'xxxx-xxxx-xxxx-1234') If the credit charge is not registered, the screen will change to the credit charge information screen.
history()
Get credit shard history. Returns `` `dict (charged_count = x, charged_amount = y) ``` as the return value.
charge(value)
I will charge.
You can enter value
in increments of 1,000 yen up to 50,000 yen.
If it exceeds 30,000 yen, the charge will be processed separately so that the second time will be at least 5,000 yen.
(Example:
50,000 yen = 30,000 yen + 20,000 yen
31,000 yen = 26,000 yen + 5,000 yen)
If a PGSE09 error occurs during processing, it will stop with a PyNanacoCreditChargeError
exception.
register(credit, profile, secure)
Set your credit card information.
Specify credit
and profile
as dict type and secure
as a string. (The interface here is not well organized and may be changed later).
python
my_card = dict(
number='xxxxxxxxxxxxxxxx',
expire_month='mm',
expire_year='yyyy',
code='xxx',
phone='xxxxxxxxxxx'
)
my_profile = dict(
name='john doe',
birthday=datetime(1980, 1, 1),
password='xxxxxxxx',
mail='[email protected]',
send_information='2'
)
secure='secure_password_here'
When you perform register
, please executelogin_credit_charge ()
in advance.
python
nanaco = PyNanaco()
nanaco.login_by_card(**my_nanaco)
nanaco.login_credit_charge()
nanaco.register(
credit=my_card,
profile=my_profile,
secure='set_secure_password_here'
)
cancel()
Unset your credit card.
You need to log in to the credit charge menu with login_credit_charge ()
in advance.
logout()
Log out.
quit()
Exit the chromedriver.
python
# -*- coding: utf-8 -*-
from datetime import datetime
from pynanaco.core import PyNanaco
# set your nanaco card information.
# (credit charge ready.)
my_nanaco = dict(
nanaco_number='xxxxxxxxxxxxxxxx',
card_number='yyyyyyy'
)
# set your nanaco card information.
# (credit charge not ready.)
my_nanaco2 = dict(
nanaco_number='xxxxxxxxxxxxxxxx',
card_number='yyyyyyy'
)
# set your credit-card information.
my_card = dict(
number='xxxxxxxxxxxxxxxx',
expire_month='mm',
expire_year='yyyy',
code='xxx',
phone='xxxxxxxxxxx'
)
# set your profile.
my_profile = dict(
name='john doe',
birthday=datetime(1980, 1, 1),
password='xxxxxxxx',
mail='[email protected]',
send_information='2'
)
def example_charge():
nanaco = PyNanaco()
nanaco.login(**my_nanaco)
nanaco.login_credit_charge('set_credit_charge_password_here')
nanaco.charge(10000)
def example_register():
nanaco = PyNanaco()
nanaco.login(**my_nanaco2)
nanaco.login_credit_charge()
nanaco.register(
credit=my_card,
profile=my_profile,
secure='set_secure_password_here'
)
def example_cancel():
nanaco = PyNanaco()
nanaco.login(**my_nanaco)
nanaco.login_credit_charge('set_credit_charge_password_here')
nanaco.cancel()
if __name__ == '__main__':
example_charge()
example_set()
example_cancel()
--The PageObjects pattern was adopted to minimize the impact of design changes on the site side, and the description of pages and methods is summarized in page.py, and the description of page element selectors is summarized in locators.py.
--Implementation of error handling (charge 15 times or more per month, charge 200,000 yen or more per month, etc.)
Recommended Posts