0.2.1: fix no hour listening time conversion bug

This commit is contained in:
Mark Joshwel 2024-05-31 23:44:36 +08:00
parent 8f0e846e95
commit 07146e1246
3 changed files with 20 additions and 10 deletions

View file

@ -36,7 +36,8 @@ from collections import Counter
from datetime import datetime, timedelta
from enum import Enum
from functools import wraps
from sys import stderr
from sys import stderr, argv
from sys import exit as sysexit
from textwrap import indent
from time import sleep
from traceback import format_exception
@ -50,6 +51,7 @@ FORMAT_TELEGRAM_PREFIX: Final[str] = " "
USER_AGENT: Final[str] = (
"Mozilla/5.0 " "(compatible; lfcircle; https://github.com/markjoshwel/lfcircle)"
)
__version__: Final[str] = "0.2.1"
GlobalTagCounter = dict[str, Counter[str]]
@ -106,6 +108,10 @@ def handle_args() -> Behaviour:
info = __doc__.strip().split("\n", maxsplit=1)[0].split(":", maxsplit=1)
default_behaviour = Behaviour()
if "--version" in argv:
print(__version__)
sysexit(0)
parser = ArgumentParser(
prog=info[0].strip(),
description=info[-1].strip(),
@ -517,17 +523,21 @@ def get_listening_report(
)
def _int(number: str) -> int:
def _int(number: str, failable: bool = False) -> int:
n = (
number.replace(",", "")
.replace("scrobbles", "")
.strip()
.lstrip("days,")
.lstrip("days")
.rstrip("hours")
.strip()
)
assert n.isnumeric()
return int(n)
if failable and n == "":
return 0
else:
assert n.isnumeric()
return int(n)
def _get_scrobbles_count(page: BeautifulSoup) -> int:
@ -558,7 +568,7 @@ def _get_listening_time_hours(page: BeautifulSoup) -> int:
days: int = _int(_d1.text)
assert (_h1 := fact.select_one(".quick-fact-data-detail")) is not None
hours: int = _int(_h1.text)
hours: int = _int(_h1.text, failable=True)
return (days * 24) + hours

8
poetry.lock generated
View file

@ -1,4 +1,4 @@
# This file is automatically @generated by Poetry 1.8.3 and should not be changed by hand.
# This file is automatically @generated by Poetry 1.6.1 and should not be changed by hand.
[[package]]
name = "beautifulsoup4"
@ -346,13 +346,13 @@ type = ["mypy (>=1.8)"]
[[package]]
name = "requests"
version = "2.32.2"
version = "2.32.3"
description = "Python HTTP for Humans."
optional = false
python-versions = ">=3.8"
files = [
{file = "requests-2.32.2-py3-none-any.whl", hash = "sha256:fc06670dd0ed212426dfeb94fc1b983d917c4f9847c863f313c9dfaaffb7c23c"},
{file = "requests-2.32.2.tar.gz", hash = "sha256:dd951ff5ecf3e3b3aa26b40703ba77495dab41da839ae72ef3c8e5d8e2433289"},
{file = "requests-2.32.3-py3-none-any.whl", hash = "sha256:70761cfe03c773ceb22aa2f671b4757976145175cdfca038c02654d061d6dcc6"},
{file = "requests-2.32.3.tar.gz", hash = "sha256:55365417734eb18255590a9ff9eb97e9e1da868d4ccd6402399eaf68af20a760"},
]
[package.dependencies]

View file

@ -1,6 +1,6 @@
[tool.poetry]
name = "lfcircle"
version = "0.2.0"
version = "0.2.1"
description = "last.fm statistics generator for your friend circle!"
authors = ["Mark Joshwel <mark@joshwel.co>"]
license = "Unlicense"