Skip to content

Commit

Permalink
geckoboard integration
Browse files Browse the repository at this point in the history
  • Loading branch information
idooo committed Aug 8, 2014
1 parent edf5bc9 commit 0841085
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 7 deletions.
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ nosetests.xml
.pydevproject

.idea/
conf/test.conf
conf/sandbox.conf
conf/*.conf

nohup.out
nohup.out
6 changes: 5 additions & 1 deletion conf/example.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@ rooms = ExampleRoom,SecondRoom

[aws]
access_key = example
secret_key = example
secret_key = example

[geckoboard]
api = example
widget = example
3 changes: 2 additions & 1 deletion pancake.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
bot = library.Bot(
conf.general['api_token'],
name=conf.general['bot_name'],
aws=conf.aws
aws=conf.aws,
gecko=conf.geckoboard
)

bot.joinRooms(conf.general['rooms'])
Expand Down
31 changes: 30 additions & 1 deletion src/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import re
import random
import inspect
import json
from time import time,sleep
from ec2_helper import EC2Helper
from simple_hipchat import HipChat
Expand All @@ -18,6 +19,7 @@ class Bot():
EC2_DOWN_CODE = 80

ec2 = None
geckoboard = None
rooms = None
joined_rooms = {}
actions = {}
Expand All @@ -31,7 +33,7 @@ class Bot():
rooms_users = {}
get_users_timeout = 5 * 60 # 5 min

def __init__(self, api_token, name=None, aws=False):
def __init__(self, api_token, name=None, aws=False, gecko=False):

self.hipster = HipChat(token=api_token)

Expand All @@ -44,6 +46,8 @@ def __init__(self, api_token, name=None, aws=False):
if aws:
self.__awsInit(aws)

self.gecko = gecko

if name:
self.name = name

Expand Down Expand Up @@ -111,6 +115,10 @@ def __setActions(self):
'action': self.__cmdGetLimit,
'help': 'Get current HipChat API limit status'
},
'/board': {
'action': self.__cmdPostToBoard,
'help': 'Post message to geckoboard'
},
'/?': {
'action': self.__cmdAsk,
'help': 'Ask me a question'
Expand Down Expand Up @@ -249,6 +257,27 @@ def __cmdTell(self, room_name, message):
message = ' '.join(message_parts[2:])
self.postMessage(room_name, "Hey {}, {}".format(recipient, message))

def __cmdPostToBoard(self, room_name, message):
message_parts = message.split(' ', 1)

if not self.gecko:
return self.postMessage(room_name, 'Have no credentials for geckoboard')

params = {
"api_key": self.gecko["api"],
"data": { "item":[{"text": message_parts[1],"type":0}] }
}
headers = {'Content-type': 'application/json'}
r = requests.post('https://push.geckoboard.com/v1/send/' + self.gecko["widget"], data=json.dumps(params), headers=headers)

if r.status_code == 200:
response = r.json()

if response['success']:
return self.postMessage(room_name, 'Message was posted to Geckoboard')

return self.postMessage(room_name, 'Something went wrong')

def __cmdGetRandomChuckPhrase(self, room_name):
message = "Can't connect to Chuck API =("
params = {'limitTo': '[nerdy]'}
Expand Down
3 changes: 2 additions & 1 deletion src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ class Settings():

rules = {
'general': ['api_token', 'rooms', 'bot_name'],
'aws': ['access_key', 'secret_key']
'aws': ['access_key', 'secret_key'],
'geckoboard': ['api', 'widget']
}

default_conf_name = 'example.conf'
Expand Down

0 comments on commit 0841085

Please sign in to comment.