Esempio n. 1
0
def runEmailLink(startDate, endDate):
    

    res = ommc.getSurveyAllData(startDate, endDate)
    resObject = res.json()

    mergevars = dex.getMailchimpOtherMergeVars() 
    ''' e.g.: {  'POSTAL': ['zip', 'zipcode', 'postal']  }'''
    
    mailchimpBatch = []

    for survey in resObject: 
        emailIndex = ommc.getEmailQuestionIndex(survey)
        if emailIndex == None:
            continue; 

        mergedict = {}
        for m in mergevars.keys():
            mmIndex = ommc.getQuestionIndexFromStrings(survey, mergevars[m])
            if mmIndex != None: 
                mergedict[mmIndex] = m
        
        
        extracted = ommc.extractFieldsFromResponses(survey, emailIndex, mergedict) 
        mailchimpBatch = mailchimpBatch + extracted

    ommc.subcribeNewUsers( mailchimpBatch )
Esempio n. 2
0
def TESTextractFieldsFromResponses():
    surveySample = {
    "Id" : 48688, 
    "SurveyResponses": [
        {
            "SurveyResponseID": 1618161487,
            "Responses": [
                { "QId": 01561156, "Res": "dGVzdEB0ZXN0dHQuY29t"},
                { "QId": 1564, "Res": "0000"},
                { "QId": 456, "Res": "NDMyODc="}
            ]
        }, 
        {
            "SurveyResponseID": 4878456,
            "Responses": [
                { "QId": 445, "Res": "dGhpc0B0aGlzLmNvbQ=="},
                { "QId": 111222, "Res": "4444"},
                { "QId": 78, "Res": ""}
            ]
        }
    ]
}

    results = OMdata.extractFieldsFromResponses(surveySample, 0, {2:'ZIP'})


    '''should return:
    [
        {
            'merge_vars': {
                'LOCATION': 'Baltimore', 
                'zip': '43287'
            }, 

            'email': {'email': '*****@*****.**'}, 
            'email_type': 'html'
        }, 
        {
            'merge_vars': {
                'LOCATION': 'Baltimore', 
                'zip': ''
            }, 

            'email': {'email': '*****@*****.**'}, 
            'email_type': 'html'
        }
    ]
    '''

    if ( results[0]['merge_vars']['ZIP'] == '43287' and 
            results[1]['email']['email'] == '*****@*****.**'):
        print 'OMdata.extractFieldsFromResponses() [PASSES]'
    else: 
        print 'OMdata.extractFieldsFromResponses() [FAILS]'