blob: 4daad96b0bdd86d9bb188e53caf90cbdb5c684ed (
plain)
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
39
40
41
|
"""Slack stuff."""
import json
import os
from slack_sdk import WebClient
RESULTS_FILE = "results.json"
def get_slack_client():
"""Initialize the slack client."""
token = os.environ["SLACK_TOKEN"]
return WebClient(token=token)
def write_results(data):
"""Write the results to a file."""
with open(RESULTS_FILE, "w") as f:
json.dump(data, f)
def load_results():
"""Load the recent search results."""
with open(RESULTS_FILE, "r") as f:
return json.load(f)
def fetch_results():
"""Query slack for the latest results."""
c = get_slack_client()
r = c.search_messages(query="@cody", sort="timestamp")
# Write the results if
if r.data["ok"]:
write_results(r.data)
print("Search complete.")
else:
print("Failed to search.")
def write_to_database
|