GithubHelp home page GithubHelp logo

awentz4 / lpdslackbot Goto Github PK

View Code? Open in Web Editor NEW

This project forked from newsnerdsatcojmc/lpdslackbot

0.0 1.0 0.0 6.89 MB

A Slack Bot that will respond with crime statistics from the Lincoln, Neb. Police Department.

License: MIT License

Python 100.00%

lpdslackbot's Introduction

LPDSlackBot

A Slack Bot that will respond with crime statistics from the Lincoln, Neb. Police Department.

Slack Bot Guide

This requires both slackbotguide.py and LPDdispatch.sqlite to be downloaded to the same directory.

You will need to edit the python file to include your bot's ID and your API key. If you want to use the weather function, you will also need a Dark Sky API key. If you don't plan to use the weather function, delete the WEATHER_KEY = os.environ.get("WEATHER_TOKEN") line.

Slack Bot ID and API Key

You will first need to create a bot. Go here and fill out the information. It will then give you your API token. Copy that and paste it at the top of the script, replacing os.environ.get("SLACK_BOT_TOKEN").

To get the Bot ID, you'll need to query the API.

  • Make sure you have slackclient installed. Run sudo pip install slackclient in your terminal.
  • Create a new file named print_bot_id.py and fill it with the following code.
from slackclient import SlackClient


BOT_NAME = 'starterbot'

slack_client = SlackClient('SLACK_BOT_TOKEN')


if __name__ == "__main__":
    api_call = slack_client.api_call("users.list")
    if api_call.get('ok'):
        # retrieve all users so we can find our bot
        users = api_call.get('members')
        for user in users:
            if 'name' in user and user.get('name') == BOT_NAME:
                print("Bot ID for '" + user['name'] + "' is " + user.get('id'))
    else:
        print("could not find bot user with the name " + BOT_NAME)
  • Replace 'starterbot' with the name of your bot
  • Replace 'SLACK_BOT_TOKEN' with your API key

This script will get a list of users from Slack and return the ID associated with your bot. Just run python print_bot_id.py in your terminal. The printed response is your Bot ID.

You can now replace os.environ.get("BOT_ID") with your Bot ID and os.environ.get("SLACK_BOT_TOKEN") with your API key.

Running the bot

CD into the directory with slackbotguide.py and LPDdispatch.sqlite in your terminal. Then, run python slackbotguide.py.

You should see Bot connected and running!. This means your bot is now listening for any mentions of its name. Invite your bot to a Slack channel and send it a command.

When you are done running your bot, switch back to your terminal and press Ctrl+C. This will shut down the process.

lpdslackbot's People

Contributors

mattwaite avatar

Watchers

ArcusEnciel avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.