Skip to content

Instantly share code, notes, and snippets.

@gnilchee
Created February 10, 2017 17:20
Show Gist options
  • Save gnilchee/5e3afe162c37d012ca77429b7a511827 to your computer and use it in GitHub Desktop.
Save gnilchee/5e3afe162c37d012ca77429b7a511827 to your computer and use it in GitHub Desktop.
Using weatherman.py post current conditions to Slack channel using user API token.
#!/usr/bin/env python3
from slackclient import SlackClient
from configparser import ConfigParser
from weatherman import WeatherAPI
config = ConfigParser()
config.read('api_secrets.conf')
SLACK_TOKEN = config['slack']['SLACK_API_TOKEN']
weather = WeatherAPI.get_current_conditions(90210)
announce = "[WEATHER BOT] {}".format(weather)
sc = SlackClient(SLACK_TOKEN)
sc.api_call(
"chat.postMessage",
channel="#channel",
text="{}".format(announce),
as_user=True
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment