#!/usr/bin/python import MySQLdb import cgi import re import datetime import xmlrpclib #import random import cgitb #import config import Cookie import os import time import errno import hashlib from Cookie import SimpleCookie from cPickle import dump, load, HIGHEST_PROTOCOL, dumps, loads print "Content-type: text/html\n\n" #cgitb.enable() if not "HTTP_COOKIE" in os.environ: os.environ["HTTP_COOKIE"] = "" SESSION = None S_DIR = os.path.expanduser("~/.py_sessions") # expanduser for windows users S_EXT = ".ps" S_ID = "__sid__" TODAY = str(datetime.date.today()) DEBUG = [] # debug messages if not os.path.exists(S_DIR): os.makedirs(S_DIR) class NoCookiesError(Exception): pass class NotStarted(Exception): pass ################################################################################ ## ## Important stuff that should be easy to change ## ################################################################################ ############################################################################ ## Database Settings ############################################################################ mysqlhostname="" mysqlusername="" mysqlpassword="" mysqldbname="" ############################################################################ ## Path to this file for email ############################################################################ urltothisfile="" ############################################################################ ## Infusiont particular Settings ############################################################################ infusionsoftapp="" infusionsoftAPIKey="" tagID=395 #This is the tag that is associated with people who should recieve the emails for peer feedback fromAddress = "" ############################################################################ ## Time Thresholds ############################################################################ timeGreen = 90 timeYellow=240 PASSWORD="" ################################################################################ ## ## Classes ## ################################################################################ class Line(object): def __init__(self, lineNumber, whoSaidIt, whatWasSaid, timeItWasSaid="", timeSinceLastStatement=""): self.lineNumber=lineNumber self.whoSaidIt=whoSaidIt self.whatWasSaid=whatWasSaid self.timeItWasSaid=timeItWasSaid self.timeSinceLastStatement=timeSinceLastStatement self.allComplexFeedback=[] def setSimpleFeedBack(self, simpleA, simpleB): self.simpleA=simpleA self.simpleB=simpleB def addComplexFeedback(self, feedback): self.allComplexFeedback.append(feedback) class Chat(object): def __init__(self): self.Agent="" self.Agentfname="" self.Agentlinitial="" self.Customer="" self.chatID="" self.fullLog="" self.orderedLines={} self.lines=[] class ISServer: global infusionsoftapp global infusionsoftAPIKey global tagID global fromAddress def __init__(self): self.appurl = "https://" + infusionsoftapp+".infusionsoft.com:443/api/xmlrpc" self.connection = xmlrpclib.ServerProxy(self.appurl) def sendEmail(self, emailBody): """ This method will take the body of an email and mail it to all contacts who have the tag "ChatSupport" and email addresses that end in @infusionsoft.com """ contactList = self.getContacts() toAddress='~Contact.Email~' ccAddress='' bccAddress='' contentType="HTML" subject="Please Provide Feedback" htmlBody=emailBody textBody='' self.connection.APIEmailService.sendEmail(infusionsoftAPIKey, contactList, fromAddress, toAddress, ccAddress, bccAddress, contentType, subject, htmlBody, textBody) def getContacts(self): desiredResults=[] listOfDicts = self.connection.DataService.query(infusionsoftAPIKey, "ContactGroupAssign", 1000,0,{'GroupId':395},['ContactId'],"ContactId", True ) for eachEntry in listOfDicts: desiredResults.append(eachEntry['ContactId']) return desiredResults def addContact(self, fname, email): newContact={} newContact["FirstName"]=fname #newContact["LastName"]=lname newContact["Email"]=email thiscontact = self.connection.ContactService.add(infusionsoftAPIKey, newContact) self.connection.ContactService.addToGroup(infusionsoftAPIKey, thiscontact, tagID) self.connection.APIEmailService.optIn(infusionsoftAPIKey, email, "This email was opted in to recieve notifications regarding peer feedback") ################################################################################ ## ## General "What to do now" logic ##`~ ################################################################################ def guidingWhereToGo(arguments): if (arguments.has_key("chat")): if (arguments.has_key("mode")): cumulativePage(arguments["chat"].value) else: votingPage(arguments["chat"].value) elif (arguments.has_key("feedbacksubmit")): updateDatabase(arguments) elif (arguments.has_key("singlesubmit")): individualAdd() elif (arguments.has_key("multisubmit")): multiAdd() elif (arguments.has_key("singleChatSubmitted")): mainSequence(arguments["chatlog"].value, arguments["chatid"].value) elif (arguments.has_key("emailRecent")): emailUpdates() elif (arguments.has_key("signup")): server=ISServer() server.addContact(arguments['Name'].value, arguments['Email'].value) generateIndexPage() elif (arguments.has_key("deleteData")): dropall() elif (arguments.has_key("emailsignup")): signuppage() else: generateIndexPage() ################################################################################ ## ## MySQLdb connection Generator ## ################################################################################ def databaseConnection(): global mysqlhostname global mysqlusername global mysqlpassword global mysqldbname return MySQLdb.connect(host=mysqlhostname, user=mysqlusername, passwd=mysqlpassword, db=mysqldbname ) ################################################################################ ## _____ _____ _ _ ## | __ \ / ____| | | (_) ## | |__) |_ _ __ _ ___ | | __ ___ _ __ ___ _ __ __ _| |_ _ ___ _ __ ## | ___/ _` |/ _` |/ _ \ | | |_ |/ _ \ '_ \ / _ \ '__/ _` | __| |/ _ \| '_ \ ## | | | (_| | (_| | __/ | |__| | __/ | | | __/ | | (_| | |_| | (_) | | | | ## |_| \__,_|\__, |\___| \_____|\___|_| |_|\___|_| \__,_|\__|_|\___/|_| |_| ## __/ | ## |___/ ################################################################################ ############################################################################ ## ## Elements that will be used throughout the site ## ############################################################################ def mainnav(): navstr="""
""" return navstr def pagestart(pagetitle="InfusionSoft Chat PeerFeedback"): startstr="""ChatID | Date Uploaded | Provide Feedback | View feedback | Times Submitted |
%s | %s | Provide Feedback | View Feedback | %s |