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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file slacraper-0.1.0.tar.gz.
File metadata
- Download URL: slacraper-0.1.0.tar.gz
- Upload date:
- Size: 24.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b434b396cf82b41295c7811c7983aa6cc2efa56496f48149f8da8ec944bd1801
|
|
| MD5 |
2715b5407a4d1b0c875bdc2191ad27e5
|
|
| BLAKE2b-256 |
7180cf2420f2cf4cd05813e9e8c9fe297c50866829d6394b242f21781bcba7d5
|
Provenance
The following attestation bundles were made for slacraper-0.1.0.tar.gz:
Publisher:
publish.yaml on youyo/slacraper
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
slacraper-0.1.0.tar.gz -
Subject digest:
b434b396cf82b41295c7811c7983aa6cc2efa56496f48149f8da8ec944bd1801 - Sigstore transparency entry: 195294954
- Sigstore integration time:
-
Permalink:
youyo/slacraper@3873ab21cfd7a757aa38b52a1044875dd5c8713b -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/youyo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@3873ab21cfd7a757aa38b52a1044875dd5c8713b -
Trigger Event:
push
-
Statement type:
File details
Details for the file slacraper-0.1.0-py3-none-any.whl.
File metadata
- Download URL: slacraper-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8085ceab4250902e504788f8bf8dcede8395324d71b99df953d7bfabc8ad7597
|
|
| MD5 |
d8bd5cdf84c458cca7394b5501461cd4
|
|
| BLAKE2b-256 |
65fcc2190ed823f063c9095671c4696c7d4b49e593092c97c1d03e7cf01f8258
|
Provenance
The following attestation bundles were made for slacraper-0.1.0-py3-none-any.whl:
Publisher:
publish.yaml on youyo/slacraper
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
slacraper-0.1.0-py3-none-any.whl -
Subject digest:
8085ceab4250902e504788f8bf8dcede8395324d71b99df953d7bfabc8ad7597 - Sigstore transparency entry: 195294955
- Sigstore integration time:
-
Permalink:
youyo/slacraper@3873ab21cfd7a757aa38b52a1044875dd5c8713b -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/youyo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@3873ab21cfd7a757aa38b52a1044875dd5c8713b -
Trigger Event:
push
-
Statement type: