Skip to main content

slacraper

Slack のメッセージを取得するためのツールです。ライブラリとしての利用を基本としますが、CLI としても利用できます。

インストール

# pipを使用する場合
pip install slacraper

# uvを使用する場合
uv pip install slacraper

または、開発版を使用する場合:

# pipを使用する場合
pip install git+https://github.com/youyo/slacraper.git

# uvを使用する場合
uv pip install git+https://github.com/youyo/slacraper.git

uvx での実行

uvx を使用して直接実行することもできます:

# モジュールとして実行
uvx slacraper --channel general

# ソースコードから直接実行
uvx src/slacraper/cli.py --channel general

使い方

ライブラリとして

from slacraper import Slacraper

# 環境変数 SLACK_BOT_TOKEN が設定されている場合
scraper = Slacraper(channel="general")
messages = scraper.get_messages()
print(messages)
# トークンを直接指定する場合
scraper = Slacraper(channel="general", token="xoxb-your-token")

# 時間範囲を指定する場合(数値で指定)
messages = scraper.get_messages(time_range=2)  # 過去2時間のメッセージを取得

# 時間範囲を自然言語で指定する場合
messages = scraper.get_messages(time_range="1 day")  # 過去1日のメッセージを取得
messages = scraper.get_messages(time_range="1 week")  # 過去1週間のメッセージを取得
messages = scraper.get_messages(time_range="2 weeks")  # 過去2週間のメッセージを取得
print(messages)

# フィルタリングオプションを使用する場合
messages = scraper.get_messages(
    user="user_name",
    text_contains="検索キーワード",
    reaction="thumbsup",
    include_url=True
)
print(messages)

CLI として

# 環境変数 SLACK_BOT_TOKEN が設定されている場合
slacraper --channel general

# トークンを直接指定する場合
slacraper --channel general --token xoxb-your-token
# 時間範囲を自然言語で指定する場合
slacraper --channel general --time-range "1 day"  # 過去1日のメッセージを取得
slacraper --channel general --time-range "1 week"  # 過去1週間のメッセージを取得
slacraper --channel general --time-range "2 weeks"  # 過去2週間のメッセージを取得

# フィルタリングオプションを使用する場合
slacraper --channel general --user user_name --text-contains "検索キーワード" --reaction thumbsup --include-url

必要な Slack Bot のパーミッション

このツールを使用するには、Slack Bot に以下のパーミッション(スコープ)が必要です:

  • channels:read - パブリックチャンネルの一覧取得
  • groups:read - プライベートチャンネルの一覧取得
  • users:read - ユーザー情報の取得
  • channels:history - パブリックチャンネルのメッセージ履歴取得
  • groups:history - プライベートチャンネルのメッセージ履歴取得
  • team:read - ワークスペース情報の取得(メッセージ URL の生成に使用)

これらのパーミッションは、Slack API のアプリ管理画面で設定できます。

オプション

  • --channel: (必須) メッセージを取得するチャンネル名
  • --token: Slack Bot Token(環境変数 SLACK_BOT_TOKEN が設定されていない場合は必須)
  • --time-range: 時間範囲を自然言語で指定(例: "1 hour", "2 days", "1 week", "1 month")(デフォルト: "1 hour")
  • --user: 特定のユーザーのメッセージのみを取得
  • --text-contains: 特定のテキストを含むメッセージのみを取得
  • --reaction: 特定のリアクション(スタンプ)が付与されたメッセージのみを取得
  • --include-url: メッセージの URL も出力に含める

出力形式

出力は構造化 JSON フォーマットです:

[
  {
    "channel": "general",
    "user": "U12345678",
    "user_name": "username",
    "text": "メッセージ内容",
    "timestamp": "2023-01-01T12:34:56Z",
    "reactions": [
      {
        "name": "thumbsup",
        "count": 3,
        "users": ["U12345678", "U87654321", "U11223344"]
      }
    ],
    "url": "https://workspace.slack.com/archives/C12345678/p1234567890123456"
  }
]

ライセンス

MIT

Metadata

Release files for slacraper 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for slacraper 0.2.1
File Size Uploaded
slacraper-0.2.1.tar.gz 31.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for slacraper 0.2.1
File Interpreter ABI Platform
slacraper-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 45.2 kB

Release files / slacraper-0.2.1.tar.gz

Download URL slacraper-0.2.1.tar.gz
Size 31.8 kB
Tags Source
SHA-256 checksum
How to use checksums
ad3983663cd9cd9b224d40d7bdca0b1401115dc031cffc08ec252d48aca6e7d4
BLAKE2b-256 checksum
How to use checksums
9a255199e47fd5a76fcd64e43554ff324bed53581c5c99fd6cd95760191c2cd2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 12, 2025.

Transparency log

Release files / slacraper-0.2.1-py3-none-any.whl

Download URL slacraper-0.2.1-py3-none-any.whl
Size 13.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8bfbf902f1f3dd76afc2fd58c6a15b13e1ed937feaf5f42ab508c25a9bef4672
BLAKE2b-256 checksum
How to use checksums
6a07a5925d7c6ae2bcff29bd938149e93b8f37fdf0fd84189545c8fe385f3972
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 12, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page