Created
March 22, 2016 17:51
-
-
Save jeremiahmarks/5abf028b1aa3115d07d2 to your computer and use it in GitHub Desktop.
optoutform
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/local/bin/python2.7 | |
import cgi | |
import cgitb | |
cgitb.enable() | |
import xmlrpclib | |
class infusCon: | |
def __init__(self, appname, apikey): | |
self.app=appname | |
self.apikey=apikey | |
self.connection=xmlrpclib.ServerProxy("https://" + self.app + ".infusionsoft.com:443/api/xmlrpc") | |
def optoutaddress(self, emailaddress, reason = "Because Lyle Said So" ): | |
self.connection.APIEmailService.optOut(self.apikey, emailaddress, reason) | |
def htmlHead(): | |
return """ | |
<html><body>""" | |
def sortUpdate(postdata): | |
print """Content-type: text/html\n\n\n""" | |
# pagehtml = "" | |
neededfields=["appname", "apikey", "emailaddress"] | |
hasallfields=True | |
optedout = False | |
for eachfield in neededfields: | |
if eachfield not in postdata: | |
hasallfields = False | |
if hasallfields: | |
thiscon = infusCon(postdata['appname'], postdata['apikey']) | |
optedout = thiscon.optoutaddress(postdata['emailaddress']) | |
pagehtml = htmlHead() | |
if optedout: | |
pagehtml += """<div>Contact was opted out</div></br>""" | |
pagehtml += """<form method="POST"> | |
<input type="Text" name="appname"> | |
<input type="Text" name="apikey"> | |
<input type="Text" name="emailaddress"> | |
<input type="Submit" value="OptOut"> | |
</form></body></html>""" | |
print pagehtml | |
if __name__ == '__main__': | |
postdata=cgi.FieldStorage() | |
sortUpdate(postdata) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment