Exemple #1
0
def getRegionName(rjson, region):
    regionDisplayName = region
    metadata = util.getValueOrDefault(rjson, "metadata")
    if not metadata:
        return regionDisplayName

    regions = util.getValueOrDefault(metadata, "regions")
    if not regions or len(regions) == 0:
        print("Response had no region information")
    else:
        regionDisplayName = regions[0]["name"]
    return regionDisplayName
Exemple #2
0
if __name__ == "__main__":
    config = LunchbotConfig()
    client = SlackClient(config.api_key)

    cmds = buildCommands()

    if not client.rtm_connect():
        print("Failed to connect to Slack")
        exit(1)

    while True:
        time.sleep(1)
        last_read = client.rtm_read()
        if last_read:
            try:
                # get the message and the channel message was found in.
                parsed = util.getValueOrDefault(last_read[0], 'text')
                message_channel = util.getValueOrDefault(last_read[0], 'channel')
                if not parsed or not message_channel:
                    continue
                
                print("channel = " + message_channel)
                print("parsed = " + parsed)

                msg = runCommand(parsed, cmds)
                if msg:
                    client.rtm_send_message(message_channel, msg)

            except Exception as ex:
                print("Error: " + str(ex))