Skip to content

アーキテクチャ

ディレクトリ構成

pocolocoClaw/
├── .github/workflows/           # GitHub Actions スケジューラ
│   ├── post-prediction.yml      # 土日9時: 予想投稿
│   ├── post-result.yml          # 土日17時: 結果投稿
│   └── post-balance.yml         # 月曜10時: 週次レポート
├── src/
│   ├── types/index.ts           # 共通型定義
│   ├── x-client/index.ts        # X APIクライアント
│   ├── templates/               # 投稿テンプレート
│   ├── prediction/              # 予想データスクレイピング
│   ├── result/                  # レース結果・的中判定
│   ├── balance/                 # 収支管理(JSON永続化)
│   ├── analytics/               # フォロワー分析
│   └── commands/                # CLIコマンド
├── dashboard/                   # 管理ダッシュボード(Next.js)
├── docs/                        # 設計書(VitePress)
└── data/                        # 収支・分析データ

モジュール依存関係

templates ◀─── commands ───▶ x-client
    ▲              │
    │              ▼
    ├──── prediction ──▶ 競馬予想サイト (HTTP)
    │              │
    ├──── result ◀──┘

    └──── balance ◀──── result

analytics ◀──────────── x-client

型定義

typescript
// 買い目の種別
type BetType = 'win' | 'place' | 'quinella' | 'wide'
             | 'exacta' | 'trio' | 'trifecta'

// 買い目データ
interface Bet {
  betType: BetType
  selection: number[]  // 馬番の配列
  amount: number       // 投資金額
}

// レース情報
interface RaceInfo {
  date: string         // YYYY-MM-DD
  venue: string        // 開催場
  raceNumber: number
  raceName: string
}

// 予想データ
interface Prediction {
  race: RaceInfo
  bets: Bet[]
}

// レース結果
interface RaceResult {
  race: RaceInfo
  order: number[]       // 着順の馬番
  payouts: PayoutInfo[]
}

// 収支レコード
interface BetRecord {
  date: string
  venue: string
  raceNumber: number
  raceName: string
  betType: BetType
  selection: number[]
  investment: number
  payout: number
  profit: number
}

// 収支サマリー
interface BalanceSummary {
  period: string
  totalInvestment: number
  totalPayout: number
  profit: number
  returnRate: number
  totalBets: number
  wins: number
  hitRate: number
}

外部連携

競馬予想サイト

  • URL: https://horse-racing-data-checker.pages.dev/
  • 取得方法: HTTPリクエスト + cheerioによるHTMLパース
  • トップページ: レース一覧(a[href*="analysis_"]
  • レースページ: analysis_YYYYCCKKDDRR.html 形式
  • データ: 予想印(◎○▲△×)、買い目ガイド(単勝〜三連単)

X API

  • ライブラリ: twitter-api-v2
  • 認証: OAuth 1.0a(Consumer Key + Access Token)
  • 機能: ツイート投稿、スレッド投稿、リプライ、フォロワー数取得