Skip to content

Commit

Permalink
Merge pull request #35 from Jim137/develop_fix
Browse files Browse the repository at this point in the history
Add test files
  • Loading branch information
Jim137 authored Oct 13, 2023
2 parents d8bc325 + f30795e commit 95e002a
Show file tree
Hide file tree
Showing 14 changed files with 308 additions and 237 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Test

on:
pull_request:
push:
branches:
- master

jobs:
lint_and_test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11']
steps:
- uses: actions/checkout@v2
with:
submodules: recursive
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Set Variables
id: set_variables
shell: bash
run: |
echo "PY=$(python -c 'import hashlib, sys;print(hashlib.sha256(sys.version.encode()+sys.executable.encode()).hexdigest())')" >> $GITHUB_OUTPUT
echo "PIP_CACHE=$(pip cache dir)" >> $GITHUB_OUTPUT
- name: Cache PIP
uses: actions/cache@v3
with:
path: ${{ steps.set_variables.outputs.PIP_CACHE }}
key: ${{ runner.os }}-pip-${{ steps.set_variables.outputs.PY }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install flake8
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics --per-file-ignores="paifulogger/log.py:C901,F401,F403,F405,E501 paifulogger/src/__init__.py:F401 test/test.py:E402" --exclude mjlog2mjai
- name: Test with test
run: python ./test/test.py
47 changes: 3 additions & 44 deletions launch.py
Original file line number Diff line number Diff line change
@@ -1,48 +1,7 @@
import argparse
import sys

from paifulogger import log


def main():
parser = argparse.ArgumentParser()
parser.add_argument("url",
nargs='*',
help="URL of the match.")
parser.add_argument("-l",
"--lang",
type=str,
help="Language of the program and output files. Default is English. Available languages: English(en), 繁體中文(zh_tw), 简体中文(zh), 日本語(ja).")
parser.add_argument("-f",
"--format",
type=str,
help="Format of the output file. Default is xlsx. Available formats: xlsx, html.",
choices=['xlsx', 'html'])
parser.add_argument("-a",
"--all-formats",
action="store_true",
help="Output all formats.")
parser.add_argument("-r",
"--remake",
action="store_true",
help="Remake the log file from url_log.h5 (past logging log). Use this when the program is updated, changing format or language of the log file, or the log file is missing. Note that this will overwrite the log file.")
parser.add_argument("-o",
"--output",
type=str,
help="Output directory. Default is './'.")
parser.add_argument("-v",
"--version",
action="store_true",
help="Show version of the program. If this is used, all other arguments will be ignored and the program will be closed.")
parser.add_argument("--mjai",
action="store_true",
help="Output MJAI format paifu.")
# Args for Debugging
parser.add_argument("--ignore-duplicated",
action="store_true",
help=argparse.SUPPRESS)
args = parser.parse_args()
log.log(args)


if __name__ == '__main__':
main()
if __name__ == "__main__":
sys.exit(log.main())
47 changes: 3 additions & 44 deletions paifulogger/__main__.py
Original file line number Diff line number Diff line change
@@ -1,48 +1,7 @@
import argparse
import sys

from paifulogger import log


def main():
parser = argparse.ArgumentParser()
parser.add_argument("url",
nargs='*',
help="URL of the match.")
parser.add_argument("-l",
"--lang",
type=str,
help="Language of the program and output files. Default is English. Available languages: English(en), 繁體中文(zh_tw), 简体中文(zh), 日本語(ja).")
parser.add_argument("-f",
"--format",
type=str,
help="Format of the output file. Default is xlsx. Available formats: xlsx, html.",
choices=['xlsx', 'html'])
parser.add_argument("-a",
"--all-formats",
action="store_true",
help="Output all formats.")
parser.add_argument("-r",
"--remake",
action="store_true",
help="Remake the log file from url_log.h5 (past logging log). Use this when the program is updated, changing format or language of the log file, or the log file is missing. Note that this will overwrite the log file.")
parser.add_argument("-o",
"--output",
type=str,
help="Output directory. Default is './'.")
parser.add_argument("-v",
"--version",
action="store_true",
help="Show version of the program. If this is used, all other arguments will be ignored and the program will be closed.")
parser.add_argument("--mjai",
action="store_true",
help="Output MJAI format paifu.")
# Args for Debugging
parser.add_argument("--ignore-duplicated",
action="store_true",
help=argparse.SUPPRESS)
args = parser.parse_args()
log.log(args)


if __name__ == '__main__':
main()
if __name__ == "__main__":
sys.exit(log.main())
123 changes: 65 additions & 58 deletions paifulogger/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,51 +2,51 @@
import argparse
import re
import os
import sys
from pandas import HDFStore, DataFrame

from paifulogger import __version__
from .src import *

url_reg = r'https?://tenhou\.net/\d/\?log=\d{10}gm-\w{4}-\w{4}-\w{8}&tw=\d'
url_reg = r"https?://tenhou\.net/\d/\?log=\d{10}gm-\w{4}-\w{4}-\w{8}&tw=\d"


def remove_old_paifu(paifu_str: str, format):
if os.path.exists(f'./{paifu_str}.{format}'):
os.remove(f'./{paifu_str}.{format}')
if os.path.exists(f"./{paifu_str}.{format}"):
os.remove(f"./{paifu_str}.{format}")
return None


def log(args):

# get version and exit
if args.version:
print('Tenhou-Paifu-Logger', __version__)
print("Tenhou-Paifu-Logger", __version__)
return None

# get language
if args.lang:
lang = args.lang
else:
lang = 'en'
lang = "en"
main_path = os.path.dirname(os.path.abspath(__file__))
local_str = localized_str(lang, main_path)

# get output directory
if args.output:
output = args.output
else:
output = os.path.abspath('./')
output = os.path.abspath("./")

# get urls
urls = []
if args.remake:
store = HDFStore(f'{output}/{local_str.paifu}/url_log.h5')
if 'url' not in store:
store['url'] = DataFrame(columns=['url'])
urlstore = store['url']['url'].values
store = HDFStore(f"{output}/{local_str.paifu}/url_log.h5")
if "url" not in store:
store["url"] = DataFrame(columns=["url"])
urlstore = store["url"]["url"].values
for url in urlstore:
if not re.match(url_reg, url):
urls.append('https://'+url)
urls.append("https://" + url)
continue
urls.append(url)
store.close()
Expand All @@ -60,22 +60,22 @@ def log(args):
if args.format:
format = args.format
else:
format = 'xlsx'
format = "xlsx"

# if remake, remove old files
if args.remake:
paifu_str3 = local_str.paifu + '/' + local_str.sanma + local_str.paifu
paifu_str4 = local_str.paifu + '/' + local_str.yonma + local_str.paifu
paifu_str3 = local_str.paifu + "/" + local_str.sanma + local_str.paifu
paifu_str4 = local_str.paifu + "/" + local_str.yonma + local_str.paifu
try:
if args.all_formats:
remove_old_paifu(paifu_str3, 'html', output)
remove_old_paifu(paifu_str3, 'xlsx', output)
remove_old_paifu(paifu_str4, 'html', output)
remove_old_paifu(paifu_str4, 'xlsx', output)
remove_old_paifu(paifu_str3, "html", output)
remove_old_paifu(paifu_str3, "xlsx", output)
remove_old_paifu(paifu_str4, "html", output)
remove_old_paifu(paifu_str4, "xlsx", output)
else:
remove_old_paifu(paifu_str3, format, output)
remove_old_paifu(paifu_str4, format, output)
except:
except OSError:
pass

# log
Expand All @@ -93,9 +93,9 @@ def log(args):
if args.all_formats:
log_into_html(paifu, local_str, output)
log_into_xlsx(paifu, local_str, output)
elif format == 'xlsx':
elif format == "xlsx":
log_into_xlsx(paifu, local_str, output)
elif format == 'html':
elif format == "html":
log_into_html(paifu, local_str, output)
if args.remake:
pass
Expand All @@ -109,42 +109,49 @@ def log(args):
print(local_str.hint_tw, url)


if __name__ == '__main__':
def main():
parser = argparse.ArgumentParser()
parser.add_argument("url",
nargs='*',
help="URL of the match.")
parser.add_argument("-l",
"--lang",
type=str,
help="Language of the program and output files. Default is English. Available languages: English(en), 繁體中文(zh_tw), 简体中文(zh), 日本語(ja).")
parser.add_argument("-f",
"--format",
type=str,
help="Format of the output file. Default is xlsx. Available formats: xlsx, html.",
choices=['xlsx', 'html'])
parser.add_argument("-a",
"--all-formats",
action="store_true",
help="Output all formats.")
parser.add_argument("-r",
"--remake",
action="store_true",
help="Remake the log file from url_log.h5 (past logging log). Use this when the program is updated, changing format or language of the log file, or the log file is missing. Note that this will overwrite the log file.")
parser.add_argument("-o",
"--output",
type=str,
help="Output directory. Default is './'.")
parser.add_argument("-v",
"--version",
action="store_true",
help="Show version of the program. If this is used, all other arguments will be ignored and the program will be closed.")
parser.add_argument("--mjai",
action="store_true",
help="Output MJAI format paifu.")
parser.add_argument("url", nargs="*", help="URL of the match.")
parser.add_argument(
"-l",
"--lang",
type=str,
help="Language of the program and output files. Default is English. Available languages: English(en), 繁體中文(zh_tw), 简体中文(zh), 日本語(ja).",
)
parser.add_argument(
"-f",
"--format",
type=str,
help="Format of the output file. Default is xlsx. Available formats: xlsx, html.",
choices=["xlsx", "html"],
)
parser.add_argument(
"-a", "--all-formats", action="store_true", help="Output all formats."
)
parser.add_argument(
"-r",
"--remake",
action="store_true",
help="Remake the log file from url_log.h5 (past logging log). Use this when the program is updated, changing format or language of the log file, or the log file is missing. Note that this will overwrite the log file.",
)
parser.add_argument(
"-o", "--output", type=str, help="Output directory. Default is './'."
)
parser.add_argument(
"-v",
"--version",
action="store_true",
help="Show version of the program. If this is used, all other arguments will be ignored and the program will be closed.",
)
parser.add_argument("--mjai", action="store_true", help="Output MJAI format paifu.")
# Args for Debugging
parser.add_argument("--ignore-duplicated",
action="store_true",
help=argparse.SUPPRESS)
parser.add_argument(
"--ignore-duplicated", action="store_true", help=argparse.SUPPRESS
)
args = parser.parse_args()
log(args)
return 0


if __name__ == "__main__":
sys.exit(main())
Loading

0 comments on commit 95e002a

Please sign in to comment.