Browse Source

An initial API client.

master
Bob 8 years ago
parent
commit
f89055fcf2
  1. 2
      LICENSE
  2. 43
      belay.py
  3. 2
      requirements.txt

2
LICENSE

@ -1,4 +1,4 @@
Copyright (c) <year> <owner> . 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.

43
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)

2
requirements.txt

@ -0,0 +1,2 @@
pyyaml
slackclient
Loading…
Cancel
Save