Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/kabuyoho/report trend signal #64

Merged
merged 3 commits into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/kabupy/kabuyoho/kabuyoho.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from .report_news import ReportNews
from .report_target import ReportTarget
from .report_top import ReportTop
from .report_trend_signal import ReportTrendSignal

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -50,3 +51,8 @@ def report_dps(self) -> ReportDps:
def report_news(self) -> ReportNews:
"""Report news page object"""
return ReportNews(self.website, self.security_code)

@functools.cached_property
def report_trend_signal(self) -> ReportTrendSignal:
"""Report trend signal page object"""
return ReportTrendSignal(self.website, self.security_code)
54 changes: 54 additions & 0 deletions src/kabupy/kabuyoho/report_trend_signal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
"""Scraper for https://kabuyoho.jp/sp/reportTrendSignal"""
from __future__ import annotations

import logging
import re
import urllib.parse

from ..base import Website, webpage_property
from ..errors import ElementNotFoundError
from ..util import str2float
from .kabuyoho_webpage import KabuyohoWebpage

logger = logging.getLogger(__name__)


class ReportTrendSignal(KabuyohoWebpage):
"""Report target page object."""

def __init__(self, website: Website, security_code: str | int) -> None:
self.website = website
self.security_code = str(security_code)
self.url = urllib.parse.urljoin(self.website.url, f"sp/reportTrendSignal?bcode={self.security_code}")
super().__init__()

@webpage_property
def trend_signal(self) -> str:
"""Trend signal: トレンドシグナル>今日のトレンドシグナル."""
value = self.select_one('h2:-soup-contains("トレンドシグナル") + div > table > td')
return value.text

@webpage_property
def coincident_index(self) -> float | None:
"""Coincident index: リスクオン相対指数>一致指数"""
values = self.select('h2:-soup-contains("リスクオン相対指数") + div > table > tbody > td')
if len(values) != 3:
raise ElementNotFoundError("coincident_index")
return str2float(values[0].text)

@webpage_property
def leading_index(self) -> float | None:
"""Leading index: リスクオン相対指数>先行指数"""
values = self.select('h2:-soup-contains("リスクオン相対指数") + div > table > tbody > td')
if len(values) != 3:
raise ElementNotFoundError("leading_index")
return str2float(values[1].text)

@webpage_property
def risk_on_relative_index_level(self) -> str | None:
"""Relative index: リスクオン相対指数>水準"""
values = self.select('h2:-soup-contains("リスクオン相対指数") + div > table > tbody > td')
if len(values) != 3:
raise ElementNotFoundError("relative_index")
value = re.sub(r"\s+", "", values[2].text)
return value if value != "--" else None
Loading