Created
April 26, 2016 20:28
-
-
Save Sam-Martin/db98e2bbd6a45f72bd0beeff3c09f407 to your computer and use it in GitHub Desktop.
RightGIF Integration for HipChat using AWS Lambda
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 urllib | |
import urllib2 | |
import json | |
def lambda_handler(event, context): | |
url = 'https://rightgif.com/search/web' | |
values = "text="+ event['item']['message']['message'].replace('/rightgif','').strip() | |
print values | |
req = urllib2.Request(url, headers={ 'user-agent': "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36" }, data=values) | |
response = urllib2.urlopen(req) | |
the_page = unicode(response.read(),errors='replace') | |
page_json = json.loads(the_page) | |
return { | |
"color": "green", | |
"message":page_json['url'], | |
"notify": "false", | |
"message_format": "text" | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment