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 SlackScraper

# 環境変数 SLACK_BOT_TOKEN が設定されている場合
scraper = SlackScraper(channel="general")
messages = scraper.get_messages()
print(messages)
# トークンを直接指定する場合
scraper = SlackScraper(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.0.tar.gz (30.9 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.0-py3-none-any.whl (13.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: slacraper-0.2.0.tar.gz
  • Upload date:
  • Size: 30.9 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.0.tar.gz
Algorithm Hash digest
SHA256 ed586938cd2a831c07a174860e014fd24f5cd5ded0dd205d9c72d07b4290eb84
MD5 29f2485219a2b2136c8fb919a717502e
BLAKE2b-256 f69f7079b5506b899f02ca86d40764515b5422ad7f9eb236dafad846f140601d

See more details on using hashes here.

Provenance

The following attestation bundles were made for slacraper-0.2.0.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.0-py3-none-any.whl.

File metadata

  • Download URL: slacraper-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 13.0 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ca9bc8aa99fdbf0bc6271b8a6ce34975d4bb5a543712dbead5dd88b3eb2af2d3
MD5 34bd710f70f15c59cde5dd9bdba905b1
BLAKE2b-256 f09a02225baf178d791b1ead3f1910d1a9a5d32da0bf2e2c46726c461f1486eb

See more details on using hashes here.

Provenance

The following attestation bundles were made for slacraper-0.2.0-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