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
# 過去2時間のメッセージを取得(従来の方法、互換性のため残されています)
slacraper --channel general --hours 2

# 時間範囲を自然言語で指定する場合
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

オプション

  • --channel: (必須) メッセージを取得するチャンネル名
  • --token: Slack Bot Token(環境変数 SLACK_BOT_TOKEN が設定されていない場合は必須)
  • --time-range: 時間範囲を自然言語で指定(例: "1 hour", "2 days", "1 week", "1 month")(デフォルト: "1 hour")
  • --hours: (非推奨) 何時間前までのメッセージを取得するか
  • --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.1.1.tar.gz (24.3 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.1.1-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for slacraper-0.1.1.tar.gz
Algorithm Hash digest
SHA256 ddfccd9408754fb0fe245d9244ac09d3090e92a9ee6de8ad3d5588a7d914c095
MD5 a767f7ee7c9daf5450628ec4bd64d080
BLAKE2b-256 837ca3d5d7011bcce95b83441783f0ebbb2ede0425a5f9a185f667006708604c

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: slacraper-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 8.7 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.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b1cf0623b7a5cb915fdc3c01e256a81dc47799b6c417a494d66ef7297629eed1
MD5 136462baa0cd922145779cbe3f70ccc0
BLAKE2b-256 a9d74ea8fe2d9910b0099624e50c0e76d5dad5ccf0adbc961d89de2506e3ccc5

See more details on using hashes here.

Provenance

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