Esempio n. 1
0
def recent_users():
    today = date.today()
    start = today - timedelta(days=settings.LOOK_BACK_DAYS)
    users = dict((u.user_id, u) for u in User.list())
    seen = set()
    day = start
    user_order = list()

    while day <= today:
        kwargs = dict(
            date=day.strftime("%Y-%m-%d"),
            timezone=settings.BOT_TZ,
        )
        try:
            day_talk = (
                Room.history(room_id=state["team_room_id"], **kwargs) +
                Room.history(room_id=state["standup_room_id"], **kwargs)
            )
            for message in day_talk:
                if message.sort != "message":
                    continue
                from_info = getattr(message, "from")
                user_id = from_info["user_id"]
                if user_id in (u"api", state["bot_user_id"]):
                    continue
                if user_id not in seen:
                    logger.info("Added %s to the standup" % from_info["name"])
                    print "Added %s to the standup" % from_info["name"]
                    seen.add(user_id)
                if user_id in user_order:
                    del user_order[user_order.index(user_id)]
                user_order.append(user_id)
        except Exception, e:
            logger.warning(
                "error fetching history for %s: %r" % (
                    day.strftime("%Y-%m-%d"), e,
                )
            )
        day += timedelta(days=1)
Esempio n. 2
0
def recent_users():
    today = date.today()
    start = today - timedelta(days=settings.LOOK_BACK_DAYS)
    users = dict((u.user_id, u) for u in User.list())
    seen = set()
    day = start
    user_order = list()

    while day <= today:
        kwargs = dict(
            date=day.strftime("%Y-%m-%d"),
            timezone=settings.BOT_TZ,
        )
        try:
            day_talk = (
                Room.history(room_id=state["team_room_id"], **kwargs) +
                Room.history(room_id=state["standup_room_id"], **kwargs))
            for message in day_talk:
                if message.sort != "message":
                    continue
                from_info = getattr(message, "from")
                user_id = from_info["user_id"]
                if user_id in (u"api", state["bot_user_id"]):
                    continue
                if user_id not in seen:
                    logger.info("Added %s to the standup" % from_info["name"])
                    print "Added %s to the standup" % from_info["name"]
                    seen.add(user_id)
                if user_id in user_order:
                    del user_order[user_order.index(user_id)]
                user_order.append(user_id)
        except Exception, e:
            logger.warning("error fetching history for %s: %r" % (
                day.strftime("%Y-%m-%d"),
                e,
            ))
        day += timedelta(days=1)
Esempio n. 3
0
def standup_loop():
    while len(state["todo"]) and not terminate:
        recent_msgs = Room.history(
            room_id=state["standup_room_id"],
            timezone=settings.BOT_TZ,
            date="recent",
        )
        for msg in recent_msgs:
            msg_date = parse(msg.date)
            if msg_date <= state["last_checked"]:
                continue
            from_info = getattr(msg, "from")
            if from_info["user_id"] in state["users"]:
                process_message(msg)

        state["last_checked"] = msg_date
        gevent.sleep(5)

    return standup_done()
Esempio n. 4
0
def standup_loop():
    while len(state["todo"]) and not terminate:
        recent_msgs = Room.history(
            room_id=state["standup_room_id"],
            timezone=settings.BOT_TZ,
            date="recent",
        )
        for msg in recent_msgs:
            msg_date = parse(msg.date)
            if msg_date <= state["last_checked"]:
                continue
            from_info = getattr(msg, "from")
            if from_info["user_id"] in state["users"]:
                process_message(msg)

        state["last_checked"] = msg_date
        gevent.sleep(5)

    return standup_done()
Esempio n. 5
0
    _deprecated_last_message_time = hipchat_log.get("last_message_time",0)
    if _deprecated_last_message_time > 0:
      hipchat_log.pop("last_message_time",None)
      last_message_times = {}
      for hipchat_room in hipchat_rooms:
        last_message_times[hipchat_room.name] = _deprecated_last_message_time
        hipchat_log["last_message_times"] = last_message_times

  for hipchat_room in hipchat_rooms:
    terms = []
    last_message_time = last_message_times.get(hipchat_room.name, 0)

    most_recent_message_date = None

    try:
      recent_messages = Room.history(room_id=hipchat_room.room_id, date="recent")
    except Exception, e:
      print e
      time.sleep(20)
      continue

    for m in recent_messages:
      user = getattr(m, 'from')
      user_name = user.get('name')
      user_id = user.get('user_id',None)
      if user_id == "api" or user_name == my_username:
        continue

      try:
        message = getattr(m, 'message')
        message_date_string = getattr(m, 'date')
Esempio n. 6
0
	global cfg_file
	cfg = ConfigObj(cfg_file)
	cfg['since'] = mktime(datetime.now().timetuple())
	cfg.write()

def is_since(m, since):
	dt = datetime.strptime(m.date[:-5], "%Y-%m-%dT%H:%M:%S")
	return dt >= since 

def notify(n, m):
	n.update(m.__getattribute__('from')['name'], m.message)
	n.show()
	sleep(3)

cfg_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'hipchat.cfg')

init_cfg()

if not pynotify.init("hipchat"):
	sys.exit(1)

n = pynotify.Notification("hipchat", "firing up")

x={"room_id": hipchat.config.room_id, "date": hipchat.config.since.strftime("%Y-%m-%d"), "timezone": "Europe/London", "format": "json"}

history=filter((lambda msg: is_since(msg, hipchat.config.since)), Room.history(**x))

map((lambda m: notify(n,m)), history)

write_cfg()
Esempio n. 7
0
            for hipchat_room in hipchat_rooms:
                last_message_times[
                    hipchat_room.name] = _deprecated_last_message_time
                hipchat_log["last_message_times"] = last_message_times

    for hipchat_room in hipchat_rooms:
        terms = []
        if last_message_times == None:
            last_message_time = 0
        else:
            last_message_time = last_message_times.get(hipchat_room.name, 0)

        most_recent_message_date = None

        try:
            recent_messages = Room.history(room_id=hipchat_room.room_id,
                                           date="recent")
        except Exception, e:
            print e
            time.sleep(20)
            continue

        for m in recent_messages:
            user = getattr(m, 'from')
            user_name = user.get('name')
            user_id = user.get('user_id', None)
            if user_id == "api" or user_name == my_username:
                continue

            try:
                message = getattr(m, 'message')
                message_date_string = getattr(m, 'date')