diff options
author | Cody Hiar <cody@hiar.ca> | 2021-02-03 14:29:24 -0700 |
---|---|---|
committer | Cody Hiar <cody@hiar.ca> | 2021-02-03 14:29:24 -0700 |
commit | 2b007a5a500b635ddcfe4b9a512777f3d21fa6b6 (patch) | |
tree | 7a9ccb2d41222fc571c6d08b169d4946e26c130c /main.py |
Initial commit of project
Diffstat (limited to 'main.py')
-rw-r--r-- | main.py | 41 |
1 files changed, 41 insertions, 0 deletions
@@ -0,0 +1,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 |