From f812e5c7d1cfe0d681444cd503809458319363d3 Mon Sep 17 00:00:00 2001 From: kunmosky1 <38534710+kunmosky1@users.noreply.github.com> Date: Thu, 30 Dec 2021 22:13:53 +0900 Subject: [PATCH 1/3] change parse_datetime --- pybotters/models/gmocoin.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pybotters/models/gmocoin.py b/pybotters/models/gmocoin.py index e068f21..0d6e956 100644 --- a/pybotters/models/gmocoin.py +++ b/pybotters/models/gmocoin.py @@ -3,6 +3,7 @@ import asyncio import logging from datetime import datetime, timezone +from dateutil import parser from decimal import Decimal from enum import Enum, auto from typing import Any, Awaitable, Optional, cast @@ -23,7 +24,14 @@ def parse_datetime(x: Any) -> datetime: if isinstance(x, str): - return datetime.strptime(x, "%Y-%m-%dT%H:%M:%S.%f%z") + try: + exec_date = x.replace('T', ' ')[:-1] + exec_date = exec_date + '00000000' + dt = datetime(int(exec_date[0:4]), int(exec_date[5:7]), int(exec_date[8:10]), + int(exec_date[11:13]), int(exec_date[14:16]), int(exec_date[17:19]), int(exec_date[20:26])) + except Exception as e: + dt = parser.parse(x) + return dt else: raise ValueError(f'x only support str, but {type(x)} passed.') From eacdec8f533611586029b948d27231371cd0a33c Mon Sep 17 00:00:00 2001 From: MtkN1 <51289448+MtkN1@users.noreply.github.com> Date: Sun, 2 Jan 2022 05:18:48 +0000 Subject: [PATCH 2/3] Add dateutil (#107) --- poetry.lock | 29 ++++++++++++++++++++++++++++- pyproject.toml | 1 + 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/poetry.lock b/poetry.lock index c44e92e..03e9da7 100644 --- a/poetry.lock +++ b/poetry.lock @@ -323,6 +323,17 @@ pytest = ">=5.0" [package.extras] dev = ["pre-commit", "tox", "pytest-asyncio"] +[[package]] +name = "python-dateutil" +version = "2.8.2" +description = "Extensions to the standard Python datetime module" +category = "main" +optional = false +python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,>=2.7" + +[package.dependencies] +six = ">=1.5" + [[package]] name = "regex" version = "2021.4.4" @@ -348,6 +359,14 @@ typing-extensions = ">=3.7.4,<4.0.0" [package.extras] jupyter = ["ipywidgets (>=7.5.1,<8.0.0)"] +[[package]] +name = "six" +version = "1.16.0" +description = "Python 2 and 3 compatibility utilities" +category = "main" +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*" + [[package]] name = "toml" version = "0.10.2" @@ -400,7 +419,7 @@ testing = ["pytest (>=4.6)", "pytest-checkdocs (>=1.2.3)", "pytest-flake8", "pyt [metadata] lock-version = "1.1" python-versions = "^3.7" -content-hash = "6ae9251e5dbfce1b2a2bd7fcdd86fea92c078edecfd52e8736681056277c4a4a" +content-hash = "e3e8e8d7b07c9b489e6fe9bf2bb8253480f8b2a4153c6b34154fe81282010795" [metadata.files] aiohttp = [ @@ -589,6 +608,10 @@ pytest-mock = [ {file = "pytest-mock-3.6.0.tar.gz", hash = "sha256:f7c3d42d6287f4e45846c8231c31902b6fa2bea98735af413a43da4cf5b727f1"}, {file = "pytest_mock-3.6.0-py3-none-any.whl", hash = "sha256:952139a535b5b48ac0bb2f90b5dd36b67c7e1ba92601f3a8012678c4bd7f0bcc"}, ] +python-dateutil = [ + {file = "python-dateutil-2.8.2.tar.gz", hash = "sha256:0123cacc1627ae19ddf3c27a5de5bd67ee4586fbdd6440d9748f8abb483d3e86"}, + {file = "python_dateutil-2.8.2-py2.py3-none-any.whl", hash = "sha256:961d03dc3453ebbc59dbdea9e4e11c5651520a876d0f4db161e8674aae935da9"}, +] regex = [ {file = "regex-2021.4.4-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:619d71c59a78b84d7f18891fe914446d07edd48dc8328c8e149cbe0929b4e000"}, {file = "regex-2021.4.4-cp36-cp36m-manylinux1_i686.whl", hash = "sha256:47bf5bf60cf04d72bf6055ae5927a0bd9016096bf3d742fa50d9bf9f45aa0711"}, @@ -636,6 +659,10 @@ rich = [ {file = "rich-10.1.0-py3-none-any.whl", hash = "sha256:60cd6d6ea697a1704f2057e791e3062b506b5c74a6e2ad2ced71eccb37557259"}, {file = "rich-10.1.0.tar.gz", hash = "sha256:8f05431091601888c50341697cfc421dc398ce37b12bca0237388ef9c7e2c9e9"}, ] +six = [ + {file = "six-1.16.0-py2.py3-none-any.whl", hash = "sha256:8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254"}, + {file = "six-1.16.0.tar.gz", hash = "sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926"}, +] toml = [ {file = "toml-0.10.2-py2.py3-none-any.whl", hash = "sha256:806143ae5bfb6a3c6e736a764057db0e6a0e05e338b5630894a5f779cabb4f9b"}, {file = "toml-0.10.2.tar.gz", hash = "sha256:b3bda1d108d5dd99f4a20d24d9c348e91c4db7ab1b749200bded2f839ccbe68f"}, diff --git a/pyproject.toml b/pyproject.toml index 632afa8..dc014fe 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,6 +12,7 @@ python = "^3.7" aiohttp = "^3.7.4" rich = "^10.1.0" typing-extensions = "^3.10.0" +python-dateutil = "^2.8.2" [tool.poetry.dev-dependencies] pytest = "^6.2.3" From 1333fc28d4e793474e221536a4cb106d216c09a7 Mon Sep 17 00:00:00 2001 From: MtkN1 <51289448+MtkN1@users.noreply.github.com> Date: Sun, 2 Jan 2022 05:19:13 +0000 Subject: [PATCH 3/3] Apply flake8, black (#107) --- pybotters/models/gmocoin.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/pybotters/models/gmocoin.py b/pybotters/models/gmocoin.py index 0d6e956..2df1f10 100644 --- a/pybotters/models/gmocoin.py +++ b/pybotters/models/gmocoin.py @@ -27,9 +27,16 @@ def parse_datetime(x: Any) -> datetime: try: exec_date = x.replace('T', ' ')[:-1] exec_date = exec_date + '00000000' - dt = datetime(int(exec_date[0:4]), int(exec_date[5:7]), int(exec_date[8:10]), - int(exec_date[11:13]), int(exec_date[14:16]), int(exec_date[17:19]), int(exec_date[20:26])) - except Exception as e: + dt = datetime( + int(exec_date[0:4]), + int(exec_date[5:7]), + int(exec_date[8:10]), + int(exec_date[11:13]), + int(exec_date[14:16]), + int(exec_date[17:19]), + int(exec_date[20:26]), + ) + except Exception: dt = parser.parse(x) return dt else: