Last active
March 3, 2016 14:10
-
-
Save canburak/0687682e4551076b8a34 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python | |
import time | |
import json | |
import urllib | |
import re | |
def lambda_handler(event, context): | |
lastHourDateTime = int(time.time()) - 3600 | |
url = 'https://api.typeform.com/v0/form/FORMID?key=APIKEY&completed=true&since=%s' % lastHourDateTime | |
response = urllib.urlopen(url) | |
data = json.loads(response.read()) | |
invite = False | |
sendto = [] | |
for response in data['responses']: | |
for key, value in response['answers'].iteritems(): | |
if key.encode().startswith('yesno_') and value.encode() == "1": | |
invite = True | |
if key.encode().startswith('email'): | |
email = value.encode() | |
if invite and email: | |
sendto.append( email ) | |
invite = False | |
email = "" | |
print sendto | |
for newbie in sendto: | |
tmp_fname, tmp_lname = newbie.split("@") | |
data = urllib.urlencode({ | |
'email' : newbie, | |
'channels':'DEFAULTCHANNELID', | |
'first_name': tmp_fname, | |
'last_name': tmp_lname, | |
'token':'SLACKAPITOKEN', | |
'set_active':'true', | |
'_attempts':'1' | |
}) | |
print "Trying for email %s" % newbie | |
f = urllib.urlopen('https://slack.com/api/users.admin.invite?t=%i' % int(time.time()) , data) | |
print f.read() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment