diff --git a/LICENSE b/LICENSE index 206be5d..7309778 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) . All rights reserved. +Copyright (c) 2017 Bob Bregant II. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. diff --git a/belay.py b/belay.py new file mode 100755 index 0000000..5122666 --- /dev/null +++ b/belay.py @@ -0,0 +1,43 @@ +#!/usr/bin/env python + +import sys +import os +import yaml +from slackclient import SlackClient + +import pprint + +# TODO: Logging Config, prints are just hack-y + + +# Try the usual places to store an API token +# First token wins +api_token = None +homedir = os.path.expanduser("~") +scriptdir = os.path.dirname(os.path.realpath(__file__)) + +# 1. Environment variables +if "SLACK_API_TOKEN" in os.environ: + api_token = os.environ["SLACK_API_TOKEN"] +# 2. ~/.config/slack/config.yml +elif os.path.isfile(os.path.join(homedir,".config","slack","config.yml")): + with open(os.path.join(homedir,".config","slack","config.yml"), "r") as config: + config_data = yaml.load(config) + api_token = config_data["api_token"] +# 3. ./config.yml +elif os.path.isfile(os.path.join(scriptdir,"config.yml")): + with open(os.path.join(scriptdir,"config.yml"), "r") as config: + config_data = yaml.load(config) + api_token = config_data["api_token"] + + +if not api_token: + print "ERROR: API token not found. Exiting." + sys.exit(-1) + +# Now to use that token on the API +slack = SlackClient(api_token) + +result = slack.api_call("team.integrationLogs") +pp = pprint.PrettyPrinter(indent=4) +pp.pprint(result) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..ced4035 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +pyyaml +slackclient