Skip to content

Commit c9b03e1

Browse files
authored
Merge pull request #32 from Jim137/master
v0.3.3a-CLI
2 parents e9f403a + fc691cc commit c9b03e1

21 files changed

+108
-51
lines changed

.github/workflows/publish-to-pypi.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,18 @@ name: Publish Python 🐍 distributions 📦 to PyPI
22

33
on:
44
release:
5-
types: [created]
5+
types: [published]
6+
7+
workflow_dispatch:
68

79
jobs:
810
build-n-publish:
911
name: Build and publish Python 🐍 distributions 📦 to PyPI
1012
runs-on: ubuntu-latest
1113
steps:
1214
- uses: actions/checkout@v3
15+
with:
16+
submodules: recursive
1317
- name: Set up Python
1418
uses: actions/setup-python@v4
1519
with:

.github/workflows/publish-to-test-pypi.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ jobs:
1111
runs-on: ubuntu-latest
1212
steps:
1313
- uses: actions/checkout@v3
14+
with:
15+
submodules: recursive
1416
- name: Set up Python
1517
uses: actions/setup-python@v4
1618
with:

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "paifulogger/src/mjlog2mjai"]
2+
path = paifulogger/src/mjlog2mjai
3+
url = https://github.com/fstqwq/mjlog2mjai.git

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Tenhou Paifu Logger
22

3-
[<img src="https://img.shields.io/pypi/v/Tenhou-Paifu-Logger?style=plastic"> <img src="https://img.shields.io/pypi/wheel/Tenhou-Paifu-Logger?style=plastic">](https://pypi.org/project/Tenhou-Paifu-Logger/) [<img src="https://img.shields.io/github/stars/Jim137/Tenhou-Paifu-Logger?style=plastic">](https://github.com/Jim137/Tenhou-Paifu-Logger/) [<img src="https://img.shields.io/github/downloads/Jim137/Tenhou-Paifu-Logger/total?style=plastic">](https://github.com/Jim137/Tenhou-Paifu-Logger/releases) ![GitHub](https://img.shields.io/github/license/Jim137/Tenhou-Paifu-Logger?style=plastic)
3+
[<img src="https://img.shields.io/pypi/v/PaifuLogger?style=plastic"> <img src="https://img.shields.io/pypi/wheel/PaifuLogger?style=plastic">](https://pypi.org/project/Tenhou-Paifu-Logger/) [<img src="https://img.shields.io/github/stars/Jim137/Tenhou-Paifu-Logger?style=plastic">](https://github.com/Jim137/Tenhou-Paifu-Logger/) [<img src="https://img.shields.io/github/downloads/Jim137/Tenhou-Paifu-Logger/total?style=plastic">](https://github.com/Jim137/Tenhou-Paifu-Logger/releases) ![GitHub](https://img.shields.io/github/license/Jim137/Tenhou-Paifu-Logger?style=plastic)
44

55
Logging tenhou paifu into excel or html file with some key information.
66

@@ -16,7 +16,7 @@ If you like this project, please leave a star. It will be a great encouragement
1616
1717
>>i. Clone the repository or download the [latest release](https://github.com/Jim137/Tenhou-Paifu-Logger/releases/latest).
1818
19-
git clone https://github.com/Jim137/Tenhou-Paifu-Logger.git
19+
git clone https://github.com/Jim137/Tenhou-Paifu-Logger.git
2020

2121
>>ii. Copy the paifu URL from tenhou.net to clipboard.
2222
>>iii. Open `runlog-user.bat`.
@@ -25,16 +25,16 @@ If you like this project, please leave a star. It will be a great encouragement
2525
2626
>>i. Open command line and type
2727
28-
pip install Tenhou-Paifu-Logger
28+
pip install PaifuLogger
2929

3030
>>ii. Copy the paifu URL from tenhou.net to clipboard. And type
3131
3232
log -l [language] -o [output directory] [paifu URLs]
3333

34-
2. Once ![1675261153312](READMEs/image/README/1675261153312.png) appears, paste the paifu URL and press Enter.\
34+
2. Once ![1675261153312](https://github.com/Jim137/Tenhou-Paifu-Logger/raw/master/READMEs/image/README/1675261153312.png) appears, paste the paifu URL and press Enter.\
3535
Note: In the latest version, you can input multiple URLs at once, separated by whatever you like. If you are lazy, you can just paste w/o anything.
36-
3. After ![1675264143738](READMEs/image/README/1675264143738.png) appears, the paifu is successfully logged.
37-
4. When ![1675261153312](READMEs/image/README/1675261153312.png) appears again, you can paste the next the URL.
36+
3. After ![1675264143738](https://github.com/Jim137/Tenhou-Paifu-Logger/raw/master/READMEs/image/README/1675264143738.png) appears, the paifu is successfully logged.
37+
4. When ![1675261153312](https://github.com/Jim137/Tenhou-Paifu-Logger/raw/master/READMEs/image/README/1675261153312.png) appears again, you can paste the next the URL.
3838

3939
## Features
4040
* [x] Log paifu into excel or html file with some key information.

READMEs/README_ja.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Tenhou Paifu Logger
22

3-
[<img src="https://img.shields.io/pypi/v/Tenhou-Paifu-Logger?style=plastic"> <img src="https://img.shields.io/pypi/wheel/Tenhou-Paifu-Logger?style=plastic">](https://pypi.org/project/Tenhou-Paifu-Logger/) [<img src="https://img.shields.io/github/stars/Jim137/Tenhou-Paifu-Logger?style=plastic">](https://github.com/Jim137/Tenhou-Paifu-Logger/) [<img src="https://img.shields.io/github/downloads/Jim137/Tenhou-Paifu-Logger/total?style=plastic">](https://github.com/Jim137/Tenhou-Paifu-Logger/releases) ![GitHub](https://img.shields.io/github/license/Jim137/Tenhou-Paifu-Logger?style=plastic)
3+
[<img src="https://img.shields.io/pypi/v/PaifuLogger?style=plastic"> <img src="https://img.shields.io/pypi/wheel/PaifuLogger?style=plastic">](https://pypi.org/project/Tenhou-Paifu-Logger/) [<img src="https://img.shields.io/github/stars/Jim137/Tenhou-Paifu-Logger?style=plastic">](https://github.com/Jim137/Tenhou-Paifu-Logger/) [<img src="https://img.shields.io/github/downloads/Jim137/Tenhou-Paifu-Logger/total?style=plastic">](https://github.com/Jim137/Tenhou-Paifu-Logger/releases) ![GitHub](https://img.shields.io/github/license/Jim137/Tenhou-Paifu-Logger?style=plastic)
44

55
ExcelまたはHTMLファイルに天鳳の牌譜をいくつかの主要情報とともに記録します。
66

@@ -25,16 +25,16 @@ ExcelまたはHTMLファイルに天鳳の牌譜をいくつかの主要情報
2525
2626
>>i. コマンドラインを開き、次のコマンドを入力します。
2727
28-
pip install Tenhou-Paifu-Logger
28+
pip install PaifuLogger
2929

3030
>>ii. 天鳳.netから牌譜のURLをクリップボードにコピーします。次に、次のコマンドを入力します。
3131
3232
log -l [言語] -o [出力ディレクトリ] [牌譜のURL]
3333

34-
1. 一度 ![Enter URLs](image/README_ja/enter_url.png) が表示されると、牌譜のURLを貼り付けてEnterキーを押します。\
34+
2. 一度 ![Enter URLs](image/README_ja/enter_url.png) が表示されると、牌譜のURLを貼り付けてEnterキーを押します。\
3535
注意: 最新バージョンでは、一度に複数のURLを任意の区切り文字で区切って入力できます。 pre> 怠け者の場合は、何も貼り付けないでください。
36-
1. ![Recorded](image/README_ja/recorded.png) が表示された後、牌譜は正常に記録されます。
37-
2. 再び ![Enter URLs](image/README_ja/enter_url.png) が表示されると、次のURLを貼り付けることができます。
36+
3. ![Recorded](image/README_ja/recorded.png) が表示された後、牌譜は正常に記録されます。
37+
4. 再び ![Enter URLs](image/README_ja/enter_url.png) が表示されると、次のURLを貼り付けることができます。
3838

3939
## 機能
4040
* [x] いくつかの主要情報とともに牌譜をExcelまたはHTMLファイルに記録します。

READMEs/README_zh.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# 天鳳牌譜記錄器
22

3-
[<img src="https://img.shields.io/pypi/v/Tenhou-Paifu-Logger?style=plastic"> <img src="https://img.shields.io/pypi/wheel/Tenhou-Paifu-Logger?style=plastic">](https://pypi.org/project/Tenhou-Paifu-Logger/) [<img src="https://img.shields.io/github/stars/Jim137/Tenhou-Paifu-Logger?style=plastic">](https://github.com/Jim137/Tenhou-Paifu-Logger/) [<img src="https://img.shields.io/github/downloads/Jim137/Tenhou-Paifu-Logger/total?style=plastic">](https://github.com/Jim137/Tenhou-Paifu-Logger/releases) ![GitHub](https://img.shields.io/github/license/Jim137/Tenhou-Paifu-Logger?style=plastic)
3+
[<img src="https://img.shields.io/pypi/v/PaifuLogger?style=plastic"> <img src="https://img.shields.io/pypi/wheel/PaifuLogger?style=plastic">](https://pypi.org/project/Tenhou-Paifu-Logger/) [<img src="https://img.shields.io/github/stars/Jim137/Tenhou-Paifu-Logger?style=plastic">](https://github.com/Jim137/Tenhou-Paifu-Logger/) [<img src="https://img.shields.io/github/downloads/Jim137/Tenhou-Paifu-Logger/total?style=plastic">](https://github.com/Jim137/Tenhou-Paifu-Logger/releases) ![GitHub](https://img.shields.io/github/license/Jim137/Tenhou-Paifu-Logger?style=plastic)
44

55
快速記錄天鳳牌譜的工具。
66

@@ -13,7 +13,7 @@
1313

1414
`git clone https://github.com/Jim137/Tenhou-Paifu-Logger.git`
1515

16-
`pip install Tenhou-Paifu-Logger`
16+
`pip install PaifuLogger`
1717

1818
2. 首次使用時,右鍵編輯 `runlog-user.bat` (Linux用戶則 `runlog-user.sh` ),在set LANG= (export LANG=)後加上語言代碼 `zh_tw`,保存後運行此檔案。
1919
使用pip則運行以下命令。

launch.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def main():
1111
parser.add_argument("-l",
1212
"--lang",
1313
type=str,
14-
help="Language of the program and output files. Default is English. Available languages: English(en), 繁體中文(zh_tw).")
14+
help="Language of the program and output files. Default is English. Available languages: English(en), 繁體中文(zh_tw), 简体中文(zh), 日本語(ja).")
1515
parser.add_argument("-f",
1616
"--format",
1717
type=str,
@@ -33,6 +33,9 @@ def main():
3333
"--version",
3434
action="store_true",
3535
help="Show version of the program. If this is used, all other arguments will be ignored and the program will be closed.")
36+
parser.add_argument("--mjai",
37+
action="store_true",
38+
help="Output MJAI format paifu.")
3639
# Args for Debugging
3740
parser.add_argument("--ignore-duplicated",
3841
action="store_true",

paifulogger/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.3.2"
1+
__version__ = "0.3.3a"

paifulogger/__main__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def main():
1111
parser.add_argument("-l",
1212
"--lang",
1313
type=str,
14-
help="Language of the program and output files. Default is English. Available languages: English(en), 繁體中文(zh_tw).")
14+
help="Language of the program and output files. Default is English. Available languages: English(en), 繁體中文(zh_tw), 简体中文(zh), 日本語(ja).")
1515
parser.add_argument("-f",
1616
"--format",
1717
type=str,
@@ -33,6 +33,9 @@ def main():
3333
"--version",
3434
action="store_true",
3535
help="Show version of the program. If this is used, all other arguments will be ignored and the program will be closed.")
36+
parser.add_argument("--mjai",
37+
action="store_true",
38+
help="Output MJAI format paifu.")
3639
# Args for Debugging
3740
parser.add_argument("--ignore-duplicated",
3841
action="store_true",

paifulogger/localizations/en.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,7 @@
1313
"excelE": 17,
1414
"sanma": "Sanma",
1515
"yonma": "",
16-
"hint_duplicate": "The match is duplicated."
16+
"hint_duplicate": "The match is duplicated.",
17+
"sanma_mjai_error": "The Sanma match does not support Mjai format.",
18+
"log2mjai_import_error": "The submodule \"mjlog2mjai\" not found. Please run `git pull --recurse-submodules`"
1719
}

paifulogger/localizations/ja.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,7 @@
1313
"excelE": 11,
1414
"sanma": "三麻",
1515
"yonma": "四麻",
16-
"hint_duplicate": "既にこの牌譜は記録されています"
16+
"hint_duplicate": "既にこの牌譜は記録されています",
17+
"sanma_mjai_error": "三麻の対局ではまだmjai牌譜形式はサポートされていません",
18+
"log2mjai_import_error": "サブモジュール「mjlog2mjai」が見つかりません。`git pull --recurse-submodules`コマンドを実行してください。"
1719
}

paifulogger/localizations/zh.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,7 @@
1313
"excelE": 11,
1414
"sanma": "三麻",
1515
"yonma": "四麻",
16-
"hint_duplicate": "已记录过此牌谱"
16+
"hint_duplicate": "已记录过此牌谱",
17+
"sanma_mjai_error": "三麻对局尚不持mjai牌谱格式",
18+
"log2mjai_import_error": "找不到子模块 \"mjlog2mjai\"。请执行 `git pull --recurse-submodules`"
1719
}

paifulogger/localizations/zh_tw.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,7 @@
1313
"excelE": 11,
1414
"sanma": "三麻",
1515
"yonma": "四麻",
16-
"hint_duplicate": "已記錄過此牌譜"
16+
"hint_duplicate": "已記錄過此牌譜",
17+
"sanma_mjai_error": "三麻對局尚不支援mjai牌譜格式",
18+
"log2mjai_import_error": "找不到子模組 \"mjlog2mjai\"。請執行 `git pull --recurse-submodules`"
1719
}

paifulogger/log.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def log(args):
8989
print(local_str.hint_duplicate, url)
9090
continue
9191
try:
92-
paifu = get_paifu(url, local_str)
92+
paifu = get_paifu(url, local_str, output, args.mjai)
9393
if args.all_formats:
9494
log_into_html(paifu, local_str, output)
9595
log_into_xlsx(paifu, local_str, output)
@@ -117,7 +117,7 @@ def log(args):
117117
parser.add_argument("-l",
118118
"--lang",
119119
type=str,
120-
help="Language of the program and output files. Default is English. Available languages: English(en), 繁體中文(zh_tw).")
120+
help="Language of the program and output files. Default is English. Available languages: English(en), 繁體中文(zh_tw), 简体中文(zh), 日本語(ja).")
121121
parser.add_argument("-f",
122122
"--format",
123123
type=str,
@@ -139,6 +139,9 @@ def log(args):
139139
"--version",
140140
action="store_true",
141141
help="Show version of the program. If this is used, all other arguments will be ignored and the program will be closed.")
142+
parser.add_argument("--mjai",
143+
action="store_true",
144+
help="Output MJAI format paifu.")
142145
# Args for Debugging
143146
parser.add_argument("--ignore-duplicated",
144147
action="store_true",

paifulogger/src/get_paifu.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,37 @@
11
import xml.etree.ElementTree as ET
22
import os
3+
34
from .url_request_handler import url_request_handler
45
from .Paifu import Paifu
56
from .local import local_str
67

78

8-
def get_paifu(url: str, local_str: local_str):
9+
def get_paifu(url: str, local_str: local_str, output: str, mjai: bool = False):
910
response = url_request_handler(url)
1011
root = ET.fromstring(response)
1112
paifu = Paifu(url, root)
12-
if not os.path.isdir(f'./{local_str.paifu}/{paifu.go_str}/'):
13-
os.makedirs(f'./{local_str.paifu}/{paifu.go_str}/')
13+
path = f'{output}/{local_str.paifu}/{paifu.go_str}/'
14+
if not os.path.isdir(path):
15+
os.makedirs(path)
1416

1517
url = url.split('=')[1]+'='+url.split('=')[2]
16-
with open(f'./{local_str.paifu}/{paifu.go_str}/'+url+'.xml', 'w') as t:
18+
with open(path+url+'.xml', 'w') as t:
1719
t.write(response)
20+
21+
# mjai format output
22+
if mjai:
23+
if paifu.player_num == 3:
24+
print(local_str.sanma_mjai_error)
25+
return paifu
26+
27+
try:
28+
from .mjlog2mjai.parse import load_mjlog, parse_mjlog_to_mjai
29+
except ImportError:
30+
print(local_str.log2mjai_import_error)
31+
return paifu
32+
if not os.path.isdir(path+'/mjai/'):
33+
os.makedirs(path+'/mjai/')
34+
with open (path+'/mjai/'+url+'.mjson', 'w', encoding='UTF-8') as f:
35+
f.write(parse_mjlog_to_mjai(load_mjlog(path+url+'.xml')))
36+
1837
return paifu

paifulogger/src/mjlog2mjai

Submodule mjlog2mjai added at 41c544c

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ requires = ["setuptools>=61.0.0", "wheel"]
33
build-backend = "setuptools.build_meta"
44

55
[project]
6-
name = "Tenhou-Paifu-Logger"
7-
version = "0.3.2"
6+
name = "PaifuLogger"
7+
version = "0.3.3a"
88
description = "Logging tenhou paifu into excel or html file with some key information."
99
readme = "README.md"
1010
authors = [{ name = "Jim137", email = "jim@mail.jim137.eu.org" }]

runlog-user.bat

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ rem.||(
33
Set skip_pip=true will skip check pip install
44

55
Set language after LANG=, default is English
6+
English: en
67
Traditional Chinese: zh_tw
8+
Simplified Chinese: zh
9+
Japanese: ja
710

811
Set format after FORMAT=, default is Excel
912
Excel: xlsx
@@ -12,6 +15,8 @@ html: html
1215
Set ALLFORMAT=true to generate all formats
1316

1417
Set output directory after OUTPUT_DIR=, default is current directory
18+
19+
Set mjai=true to generate mjai format paifu
1520
)
1621

1722
set skip_pip=
@@ -20,5 +25,6 @@ set LANG=
2025
set FORMAT=
2126
set ALLFORMAT=
2227
set OUTPUT_DIR=
28+
set mjai=
2329

2430
call runlog.bat

runlog-user.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@
1919
# export skip_pip=
2020

2121
# Set language after LANG=, default is English
22+
# English: en
2223
# Traditional Chinese: zh_tw
24+
# Simplified Chinese: zh
25+
# Japanese: ja
2326
# export LANG=
2427

2528
# Set format after FORMAT=, default is html
@@ -33,6 +36,8 @@
3336
# Set output directory after OUTPUT_DIR=, default is current directory
3437
# export OUTPUT_DIR=
3538

39+
# Set mjai=true to generate mjai format paifu
40+
# export mjai=
3641
###########################################
3742

3843
. runlog.sh

runlog.bat

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ if not defined LANG set LANG=en
44
if not defined FORMAT set FORMAT=xlsx
55
if not defined ALLFORMAT set ALLFORMAT=false
66
if not defined OUTPUT_DIR set OUTPUT_DIR=./
7+
if not defined mjai set mjai=false
8+
9+
if %ALLFORMAT% == true (
10+
set args=-l %LANG% --all-formats -o %OUTPUT_DIR%
11+
) else (
12+
set args=-l %LANG% -f %FORMAT% -o %OUTPUT_DIR%
13+
)
14+
if %mjai% == true set args=%args% --mjai
715

816
if %skip_pip% == true goto :start
917

@@ -16,15 +24,10 @@ exit
1624

1725
:start
1826
if %ALLFORMAT% == true goto:start_all
19-
python launch.py -l %LANG% -f %FORMAT% -o %OUTPUT_DIR%
27+
python launch.py %args%
2028
if %ERRORLEVEL% == 1 goto:error
2129
goto:start
2230

23-
:start_all
24-
python launch.py -l %LANG% --all-formats -o %OUTPUT_DIR%
25-
if %ERRORLEVEL% == 1 goto:error
26-
goto:start_all
27-
2831
:error
2932
echo "Error occurred"
3033
pause

0 commit comments

Comments
 (0)