Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
shimomo committed Nov 12, 2023
0 parents commit 34f1f65
Show file tree
Hide file tree
Showing 13 changed files with 685 additions and 0 deletions.
18 changes: 18 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 4
trim_trailing_whitespace = true

[*.js]
indent_size = 2

[*.md]
trim_trailing_whitespace = false

[*.{yml,yaml}]
indent_size = 2
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/node_modules
/vendor
.phpunit.result.cache
composer.lock
package-lock.json
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2020 shimomo

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
94 changes: 94 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# Boatrace Sakura Purchaser

[![Latest Stable Version](https://poser.pugx.org/boatrace-sakura/purchaser/v/stable)](https://packagist.org/packages/boatrace-sakura/purchaser)
[![Latest Unstable Version](https://poser.pugx.org/boatrace-sakura/purchaser/v/unstable)](https://packagist.org/packages/boatrace-sakura/purchaser)
[![License](https://poser.pugx.org/boatrace-sakura/purchaser/license)](https://packagist.org/packages/boatrace-sakura/purchaser)

Boatrace Sakura Purchaserはブラウザを操作して舟券を自動購入するためのライブラリです。

## Installation
```bash
composer require boatrace-sakura/purchaser
```

## Usage
```php
<?php

require __DIR__ . '/vendor/autoload.php';

use Boatrace\Sakura\Purchaser;

// テレボートに5000円を入金して大村12Rの3連単(1-23-234)を購入する場合は以下の通りです。
// なお、加入者番号、暗証番号、認証用パスワード、投票用パスワードの部分は
// 自分のテレボート会員情報に書き換えてください。
// 場コード: 桐生 => 1, 戸田 => 2, 江戸川 => 3, ..., 唐津 => 23, 大村 => 24
// 勝式コード: 単勝 => 1, 複勝 => 2, 2連単 => 3, 2連複 => 4, 拡連複 => 5, 3連単 => 6, 3連複 => 7
Purchaser::setDepositAmount(5000) // 入金指示金額
->setSubscriberNumber('xxxxxxxx') // 加入者番号
->setPersonalIdentificationNumber('xxxx') // 暗証番号
->setAuthenticationPassword('xxxxxx') // 認証用パスワード
->setPurchasePassword('xxxxxx') // 投票用パスワード
->purchase(24, 12, 6, [ // 場コード, レース番号, 勝式コード
123 => 1500, // 組番 => 購入金額
124 => 1500, // 組番 => 購入金額
132 => 1000, // 組番 => 購入金額
134 => 1000, // 組番 => 購入金額
]);
```

## Quick Start

### Step 1
このリポジトリをクローンします。
```bash
git clone git@github.com:boatrace-sakura/purchaser.git
```

### Step 2
必要なライブラリをインストールします。
```bash
cd purchaser && composer update
```

### Step 3
加入者番号、暗証番号、認証用パスワード、投票用パスワード、買い目をそれぞれ書き換えます。
```bash
code example.php
```

### Step 4
Google Chromeの[Selenium Grid Server](https://github.com/SeleniumHQ/docker-selenium)を起動します。
```bash
docker run -d -p 4444:4444 --shm-size="2g" --name selenium-standalone-chrome selenium/standalone-chrome:4.2.2-20220622
```

### Step 5
購入プログラムを実行します。
```bash
php example.php
```

## Testing
テレボート会員情報を環境変数に設定します。
```bash
$env:SUBSCRIBER_NUMBER = "加入者番号"
$env:PERSONAL_IDENTIFICATION_NUMBER = "暗証番号"
$env:AUTHENTICATION_PASSWORD = "認証用パスワード"
$env:PURCHASE_PASSWORD = "投票用パスワード"
```

Selenium Serverを起動します。
```bash
npm install selenium-standalone --save-dev
npx selenium-standalone install
npx selenium-standalone start
```

購入テストを実行します。
```bash
vendor/bin/phpunit
```

## License
The Boatrace Sakura Purchaser is open source software licensed under the [MIT license](LICENSE).
30 changes: 30 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "boatrace-sakura/purchaser",
"description": "The Boatrace Sakura Purchaser.",
"license": "MIT",
"type": "library",
"authors": [
{
"name": "shimomo",
"email": "developer@shimomo.net"
}
],
"require": {
"php": "^8.0",
"php-di/php-di": "^6.0",
"php-webdriver/webdriver": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "^9.0"
},
"autoload": {
"psr-4": {
"Boatrace\\Sakura\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Boatrace\\Sakura\\Tests\\": "tests/"
}
}
}
13 changes: 13 additions & 0 deletions config/definitions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

return [
'Purchaser' => \DI\create('\Boatrace\Sakura\Purchaser')->constructor(
\DI\get('MainPurchaser')
),
'MainPurchaser' => function ($container) {
return $container->get('\Boatrace\Sakura\MainPurchaser');
},
'ChromeOptions' => function ($container) {
return $container->get('\Facebook\WebDriver\Chrome\ChromeOptions');
},
];
22 changes: 22 additions & 0 deletions example.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

require __DIR__ . '/vendor/autoload.php';

use Boatrace\Sakura\Purchaser;

// テレボートに1000円を入金して大村12Rの2連単(1-2345)を購入する場合は以下の通りです。
// なお、加入者番号、暗証番号、認証用パスワード、投票用パスワードの部分は
// 自分のテレボート会員情報に書き換えてください。
// 場コード: 桐生 => 1, 戸田 => 2, 江戸川 => 3, ..., 唐津 => 23, 大村 => 24
// 勝式コード: 単勝 => 1, 複勝 => 2, 2連単 => 3, 2連複 => 4, 拡連複 => 5, 3連単 => 6, 3連複 => 7
Purchaser::setDepositAmount(1000) // 入金指示金額
->setSubscriberNumber('xxxxxxxx') // 加入者番号
->setPersonalIdentificationNumber('xxxx') // 暗証番号
->setAuthenticationPassword('xxxxxx') // 認証用パスワード
->setPurchasePassword('xxxxxx') // 投票用パスワード
->purchase(24, 12, 3, [ // 場コード, レース番号, 勝式コード
12 => 300, // 組番 => 購入金額
13 => 300, // 組番 => 購入金額
14 => 200, // 組番 => 購入金額
15 => 200, // 組番 => 購入金額
]);
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"devDependencies": {
"selenium-standalone": "^9.3.0"
}
}
26 changes: 26 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">

<testsuites>
<testsuite name="boatrace-sakura">
<directory suffix="Test.php">./tests/</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory>./src</directory>
</whitelist>
</filter>

<logging>
<log type="coverage-clover" target="./build/logs/clover.xml"/>
</logging>
</phpunit>
Loading

0 comments on commit 34f1f65

Please sign in to comment.