Skip to main content

Slack message scraper tool

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

slacraper-0.2.1.tar.gz (31.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

slacraper-0.2.1-py3-none-any.whl (13.3 kB view details)

Uploaded Python 3

File details

Details for the file slacraper-0.2.1.tar.gz.

File metadata

  • Download URL: slacraper-0.2.1.tar.gz
  • Upload date:
  • Size: 31.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for slacraper-0.2.1.tar.gz
Algorithm Hash digest
SHA256 ad3983663cd9cd9b224d40d7bdca0b1401115dc031cffc08ec252d48aca6e7d4
MD5 97b311a83a289bff13d6f59c623e9e7e
BLAKE2b-256 9a255199e47fd5a76fcd64e43554ff324bed53581c5c99fd6cd95760191c2cd2

See more details on using hashes here.

Provenance

The following attestation bundles were made for slacraper-0.2.1.tar.gz:

Publisher: publish.yaml on youyo/slacraper

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file slacraper-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: slacraper-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 13.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for slacraper-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8bfbf902f1f3dd76afc2fd58c6a15b13e1ed937feaf5f42ab508c25a9bef4672
MD5 ffc2666cb0b04393f3c57df7b795e8a1
BLAKE2b-256 6a07a5925d7c6ae2bcff29bd938149e93b8f37fdf0fd84189545c8fe385f3972

See more details on using hashes here.

Provenance

The following attestation bundles were made for slacraper-0.2.1-py3-none-any.whl:

Publisher: publish.yaml on youyo/slacraper

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page