Skip to content

Commit

Permalink
Implement wit actions and add required dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
paraita committed Dec 20, 2016
1 parent fec0c05 commit e81c7c7
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 13 deletions.
64 changes: 53 additions & 11 deletions billybob/__init__.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,74 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
import logging
import time
import sophiabus230
import datetime
from dateutil.tz import gettz
from slackclient import SlackClient
from wit import Wit


class BillyBob:

def wit_send(self, request, response):
print 'Sending to user... {0}'.format(response['text'])

def wit_get_prs(self, params):
print 'requested get_prs ! {0}'.format(params)
def _post_simple(self, channel, msg):
self.slack_client.api_call("chat.postMessage",
channel=params['context']['chan'].encode("ascii","ignore"),
text='requested get_prs !',
channel=channel,
text=msg,
as_user=True)
return {}

def wit_get_bus_tt(self, params):
print 'requested get_bus_tt ! {0}'.format(params)
def _post_fmt(self, channel, msg):
self.slack_client.api_call("chat.postMessage",
channel='G3FS40MFA',
text='requested get_bus_tt !',
channel=channel,
text="Here are the next bus passages !",
attachments=msg,
as_user=True)

def _check_intent(self, intent, key_intent):
return intent['entities'] and intent['entities'][key_intent]

def wit_get_prs(self, params):
chan = params['context']['chan'].encode("ascii", "ignore")
print 'requested get_prs ! {0}'.format(params)
if self._check_intent(params, 'pull_request'):
entities = params['entities']['pull_request']
if len(entities) == 1 and entities[0]['value']:
repo = entities[0]['value']
if repo == 'github':
self._post_simple(chan, 'You asked for the PRs from github')
elif repo == 'bitbucket':
self._post_simple(chan, "Sorry bruh I don't know how to do that yet :(")
elif repo == 'everywhere':
self._post_simple(chan, 'You asked for the PRs from github and bitbucket')
else:
self._post_simple(chan, 'WTF is that ?')
return {}

def wit_get_bus_tt(self, params):
red_color = "#ff0000"
green_color = "#36a64f"
buses = sophiabus230.get_next_buses()
attachments = []
tz = gettz('Europe/Paris')
time_now = datetime.datetime.now(tz=tz)
attachment = {}

for passage in buses:
bus_time = passage['bus_time']
diff_t = bus_time.replace(tzinfo=tz) - time_now
att_str = 'In {0} min (at {1})'.format(int(diff_t.total_seconds() / 60),
bus_time)
if passage['is_real_time']:
attachment['color'] = red_color
else:
attachment['color'] = green_color
attachment['text'] = att_str
attachment['fallback'] = att_str
attachments.append(attachment)
self._post_fmt(params['context']['chan'].encode("ascii", "ignore"), attachments)
return {}

def __init__(self, slack_token=None, wit_token=None, **kargs):
Expand Down
1 change: 0 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
from billybob import BillyBob


Expand Down
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
backports.ssl-match-hostname==3.5.0.1
beautifulsoup4==4.5.1
coverage==4.2
coveralls==1.1
docopt==0.6.2
funcsigs==1.0.2
mock==2.0.0
nose==1.3.7
pbr==1.10.0
python-dateutil==2.6.0
requests==2.12.4
simplejson==3.10.0
six==1.10.0
slackclient==1.0.4
sophiabus230==0.2
websocket-client==0.40.0
wit==4.2.0
4 changes: 3 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
packages=['billybob'],
install_requires=[
'slackclient',
'wit'
'wit',
'python-dateutil',
'sophiabus230'
],
test_suite='nose.collector',
tests_require=[
Expand Down

0 comments on commit e81c7c7

Please sign in to comment.