Exemple #1
0
 def start(self):
     if not self.__config['token'] or not self.__config['endpoint']:
         print("HipChat configuration is missing %s" % self.__config)
         raise AttributeError
     elif self.__config['endpoint']:
         return HypChat(self.__config['token'], endpoint=self.__config['endpoint'])
     else:
         return HypChat(self.__config['token'])
Exemple #2
0
 def __init__(self,
              access_token,
              room_name,
              endpoint='https://api.hipchat.com',
              notification_only=False):
     logging.Handler.__init__(self)
     if notification_only:
         self.notification = partial(HypChat(access_token,
                                             endpoint).send_notification,
                                     id_or_name=room_name)
     else:
         self.notification = partial(
             HypChat(access_token,
                     endpoint).get_room(room_name).notification)
Exemple #3
0
    def safe_init(self):
        self.channels = {}
        self.adapter_redis = DWhoAdapterRedis(self.config, prefix='hipchat')

        if 'hipchat' not in self.config['plugins']:
            return

        for channel, params in self.config['plugins']['hipchat'].iteritems():
            self.channels[channel] = {
                'conn': HypChat(**params['options']),
                'id': None,
                'name':
                "%s://%s/%s" % (self.PLUGIN_NAME, channel, params['room']),
                'room': params['room'],
                'token': params['options']['token'],
                'out': params['out'],
                'me': None,
                'storage': self.adapter_redis
            }

            ref_chan = self.channels[channel]
            ref_chan['me'] = ref_chan['conn'].fromurl(
                '{0}/v2/oauth/token/{1}'.format(ref_chan['conn'].endpoint,
                                                ref_chan['token']))
            CHANNELS.register(BotbondChannel(ref_chan))
 def __init__(self):
     """ init method, run at class creation """
     endpoint, token = self._get_token_endpoint()
     if token is None:
         raise SystemExit('Authorization token not detected! The token is '
                          'pulled from ~/.hypchat, /etc/hypchat, or the '
                          'environment variable HIPCHAT_TOKEN.')
     logger.debug("Connecting to HipChat (endpoint=%s)", endpoint)
     self.hipchat = HypChat(token, endpoint)
     logger.debug("Connected")
Exemple #5
0
 def __init__(self, options):
     self.options = options
     self.hc = HypChat(options["token"])
     self.hc.capabilities.url = "{hipchat}/capabilities".format(
         hipchat=self.options["server"])
     self.hc.emoticons.url = "{hipchat}/emoticon".format(
         hipchat=self.options["server"])
     self.hc.rooms.url = "{hipchat}/room".format(
         hipchat=self.options["server"])
     self.hc.users_url = "{hipchat}/user".format(
         hipchat=self.options["server"])
Exemple #6
0
def send_notify(data):

    hp = HypChat(__token__)
    for user in __users__:
        try:
            t_user = hp.get_user(user)
            message = wrap(data)
            t_user.message(message)
        except Exception as e:
            print e
    return True
Exemple #7
0
 def connect_to_hipchat(self):
     token = self._settings.get(["token"])
     endpoint = self._settings.get(["api_url"])
     room = self._settings.get(["room"])
     if token and room:
         self.hc = HypChat(token, endpoint=endpoint)
         self.room = lambda: self.hc.get_room(room)
         self._logger.info("Publishing to room %s via API endpoint %s" %
                           (room, endpoint))
     else:
         self.logger.warning(
             "Token and/or Room not set! Not connecting to HipChat. Please configure API TOken and HipChat room in the plugin settings."
         )
Exemple #8
0
 def __init__(self):
     self.rooms = ['Kemono - Production Deploy Notification']
     self.color = 'green'
     self.is_notify = False
     self.hip_chat = HypChat(self._get_token())
Exemple #9
0
access_token_secret=os.environ['ACCESS_TOKEN_SECRET']

hc_room_id=os.environ['HC_ROOM_ID']
hc_token=os.environ['HC_TOKEN']
hc_server=os.environ['HC_SERVER']

twitter_user=os.environ['TWITTER_USER']

api = twitter.Api(consumer_key=consumer_key,
                  consumer_secret=consumer_secret,
                  access_token_key=access_token,
                  access_token_secret=access_token_secret)

statuses = api.GetUserTimeline(screen_name=twitter_user)
latest_status = statuses[0].text

print "Latest tweet=%s" % latest_status

hc = HypChat(hc_token, endpoint=hc_server)
room = hc.get_room(hc_room_id)
topic = room['topic']

print "Current topic=%s" % topic

if topic != latest_status:
    print "Topic doesn't match, setting to: %s" % latest_status
    room.topic(latest_status)
else:
    print "Topic is already set to latest tweet, ignoring"
    pass
Exemple #10
0
 def __init__(self, token, room_name):
     self._token = token
     self._room_name = room_name
     self._hipchat_client = HypChat(token)
     self._room = self._hipchat_client.get_room(self.get_room_id(room_name))
     self._message_backend = self.message_backend_class(self._room_name)
Exemple #11
0
from dateutil.tz import tzutc
from hypchat import HypChat
import time
import json
import re
import os
from collections import OrderedDict

secret_path = sys.argv[1]

with open(secret_path) as secretf:
    token = secretf.read().rstrip()

CUTOFF_DATE = datetime.datetime(2016, 1, 1, tzinfo=tzutc())

hc = HypChat(token)


def get_active_rooms():
    rooms = hc.rooms()
    active_rooms = []
    for room in rooms['items']:
        if room['is_archived'] or re.search("Bot:|Meetings ::", room['name']):
            print("skipping " + room['name'])
            continue
        time.sleep(2)  # API rate limiting
        active_room = hc.get_room(room['id'])
        if active_room[
                'last_active'] and active_room['last_active'] > CUTOFF_DATE:
            print("appending room: " + active_room['name'])
            active_rooms.append(active_room)
Exemple #12
0
def get_hipchat_users():
    config = settings.load()
    raw_users = HypChat(config['hipchat']['token']).users()
    return raw_users['items']
    def __init__(self):
        self.jira = JIRA(server=os.environ['JIRA_INSTANCE'], basic_auth=(os.environ['JIRA_USER'], os.environ['JIRA_PASSWORD']))
        self.hipchat = HypChat(os.environ['HIPCHAT_TOKEN'], endpoint = "https://puppet.hipchat.com")

        # map of <field-id> -> <field-name>, used to make querying custom fields more readable.
        self.name_map = {field['id'] : field['name'] for field in self.jira.fields()}
Exemple #14
0
 def __init__(self, token, room_id):
     chat = HypChat(token)
     self._room = chat.get_room(room_id)
     self._latest_date = None
Exemple #15
0
def get_client(config):
    client = HypChat(config.get('hipchat', 'token'))
    return client
Exemple #16
0
#! /usr/bin/env python
# coding: utf-8
# LICENSE:
# Date:
# Author: konglx
# File:
# Description:

__author__ = 'Konglx'

from hypchat import HypChat
from tombot.common.log import logger

TOKEN = 'DZttvKCWeU4GpXxoqwJc4IG8bH636MjaCmLNZqc8'

hc = HypChat(TOKEN)

logger.debug('Hipchat rooms: {0}'.format(hc.rooms()))
logger.debug('Hipchat users: {0}'.format(hc.users()))
Exemple #17
0

def writeLine(time, name, messageLength, timeDiff, timeSinceStart):
  outFile.write(str(time))
  outFile.write(',')
  outFile.write(name)
  outFile.write(',')
  outFile.write(str(messageLength))
  outFile.write(',')
  outFile.write(str(timeDiff))
  outFile.write(',')
  outFile.write(str(timeSinceStart))
  outFile.write('\n')

if __name__ == '__main__':
  hc = HypChat(AUTH_TOKEN)

  startIndex = 0
  indexInterval = 150
  previousDate = 0
  totalTime = 0
  now = datetime.datetime.utcnow()

  totalContents = []

  # Get 8 * 150 results from the given room.
  for i in range(8):
    response = hc.get_room(roomId).history(now, maxResults=150, startIndex=startIndex)
    contents = list(response.contents())
    totalContents[:0] = contents
    startIndex += indexInterval
Exemple #18
0
 def __init__(self,
              access_token,
              room_name,
              endpoint='https://api.hipchat.com'):
     logging.Handler.__init__(self)
     self.room = HypChat(access_token, endpoint).get_room(room_name)
Exemple #19
0
    branch = 'master'

if repo_path == None:
    print 'Must enter a Git repository path. Exiting.'
    exit(-1)

# Set up HipChat stuff
hipchat_access_token = options.hipchat_token
hipchat_room_name = options.hipchat_room
hc = None
hc_room = None

if hipchat_access_token != None:
    do_hipchat = True
    print 'Will be sending messages to HipChat room: ' + hipchat_room_name
    hc = HypChat(hipchat_access_token)
    hc_room = hc.get_room(hipchat_room_name)

# Set up Slack stuff
slack_access_token = options.slack_token
slack_room_name = options.slack_room
slack = None

if slack_access_token != None:
    do_slack = True
    print 'Will be sending message to Slack channel: ' + slack_room_name
    slack = Slacker(slack_access_token)

# Set up JIRA stuff
jira_url = options.jira_url
jira_project = None