-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnightly_build_token.py
More file actions
38 lines (35 loc) · 935 Bytes
/
nightly_build_token.py
File metadata and controls
38 lines (35 loc) · 935 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import argparse
import json
import re
import requests
import sys
import time
parser = argparse.ArgumentParser(
prog="Nightly build token analyzer",
description="Finds a token among the given messages in recent Slack history"
)
parser.add_argument(
'--token',
help='Slack bot user OAUTH token',
required=True
)
parser.add_argument(
'--channel',
help='Slack channel ID to search through',
default="C0287431S10"
)
# 20 hours ago in unix time is the cutoff
oldest = int(time.time()) - 20 * 60 * 60
args = parser.parse_args()
r = requests.get(
f'https://slack.com/api/conversations.history?channel={args.channel}&oldest={oldest}',
headers={'Authorization': f'Bearer {args.token}'}
)
r.json()
if 'messages' in r:
for message in r['messages']:
test = re.search('token: (.+)', message)
if test:
print(test.group(1))
sys.exit(0)
sys.exit(1)