Created
July 7, 2017 14:31
-
-
Save alxwrd/a85d0d6b6515e84141c8f900ff4e3cfc to your computer and use it in GitHub Desktop.
Post inspiring quotes to a slack channel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import httplib | |
import urllib2 | |
import random | |
#If you're using IronPython, the following is needed: | |
import ssl | |
import functools | |
old_init = ssl.SSLSocket.__init__ | |
@functools.wraps(old_init) | |
def init_with_tls1(self, *args, **kwargs): | |
kwargs['ssl_version'] = ssl.PROTOCOL_TLSv1 | |
old_init(self, *args, **kwargs) | |
ssl.SSLSocket.__init__ = init_with_tls1 | |
#End | |
inspro_bot = httplib.HTTPConnection("inspirobot.me") | |
inspro_bot.request("GET", "/api?generate=true") | |
resp = inspro_bot.getresponse() | |
url = resp.read() | |
modifiers = ["much", "many", "so", "very", "such"] | |
words = ["inspire", "thoughts", "wow", "timeless", "deep"] | |
data = { | |
"attachments": [ | |
{ | |
"title": "{} {}".format(random.choice(modifiers), | |
random.choice(words)), | |
"image_url": url, | |
"footer": "http://inspirobot.me" | |
} | |
] | |
} | |
req = urllib2.Request("https://hooks.slack.com/services/YOUR/SLACK/HOOK") | |
req.add_header('Content-Type', 'application/json') | |
response = urllib2.urlopen(req, json.dumps(data)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment