Created
January 2, 2021 19:23
-
-
Save codyaray/721dca0ba663e954adafc910dced293b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from slackclient import SlackClient | |
from elasticsearch import Elasticsearch | |
from plugins.elastic.elastic import CHANNEL, USER_ID, process_message, to_metric | |
from datetime import datetime | |
import yaml | |
import json | |
ELASTIC_HOST = '[your-hostname]' | |
SIZE = 1000 | |
OLDEST = 0 | |
LATEST = datetime.now() | |
config = yaml.load(file('rtmbot.conf', 'r')) | |
sc = SlackClient(config["SLACK_TOKEN"]) | |
client = Elasticsearch(ELASTIC_HOST) | |
response = json.loads(sc.api_call('channels.history', channel=CHANNEL, count=SIZE, oldest=OLDEST, latest=LATEST)) | |
for message in response['messages']: | |
if 'channel' not in message: | |
message['channel'] = CHANNEL | |
if 'user' not in message: | |
message['user'] = USER_ID | |
process_message(message) | |
while response['has_more']: | |
oldest_ts = response['messages'][-1]['ts'] | |
response = json.loads(sc.api_call('channels.history', channel=CHANNEL, count=SIZE, oldest=OLDEST, latest=oldest_ts)) | |
for message in response['messages']: | |
if 'channel' not in message: | |
message['channel'] = CHANNEL | |
if 'user' not in message: | |
message['user'] = USER_ID | |
process_message(message) | |
if 'is_limited' in response and response['is_limited']: | |
print "We have more messages that we can't access. :'(" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment