def getUserData(campaign, id): data = [] clo = campaign.lower() print "inside getUserData, "+clo+", and id: "+str(id) if clo in "external": data = get_external_data(id) print "Got external data: "+str(data) elif clo.startswith("all"): # Actually, all in campaig.lower() print "Starts with all" #cx = pymysql.connect(user='******', password='******',database='jerry_live', host="db02") cu = db.cursor() cu.execute(QUERRY[clo]) for x in cu: data.append(x) elif clo in "testing": print "Testing campaign" # data = [["919818261929","Arabic"],["917838310825","English"],["971559052361","Arabic"]] data = get_testing_sheet().get_all_values()[1:] # Gives data in list of list format, skipping the header row elif clo in "custom": print "Custom campaign" data = get_custom_sheet().get_all_values()[1:] # Gives data in list of list format, skipping the header row elif clo.startswith("cust_"): print "starts with cust_" data = get_custom_sheet(clo).get_all_values()[1:] else: print "Different: "+clo #cx = pymysql.connect(user='******', password='******',database='cerberus_live', host="db02") cu = db.cursor() cu.execute(QUERRY['other'],campaign) for x in cu: data.append(x) blocked_list = set([a[0]+','+a[1] for a in get_block_sheet().get_all_values()[1:]]) data = [a for a in data if ','.join([a[0], a[1]]) not in blocked_list] return data
def getUserData(event): """ Get the [phone, language] or [phone, language, country] for the customers """ data = [] campaign = event['campaign'] id = event['id'] clo = campaign.lower() print "inside getUserData, " + clo + ", and id: " + str(id) if clo in ["external", "segment"]: # Main priority data = get_external_data(event) print "Got external data: " + str(data) elif clo.startswith("all"): # Actually, all in campaig.lower() print "Starts with all" cu = db.cursor() cu.execute(QUERRY[clo]) for x in cu: data.append(x) elif clo in "testing": print "Testing campaign" data = get_testing_sheet().get_all_values()[1:] # Gives data in list of list format, skipping the header row elif clo in "custom": print "Custom campaign" data = get_custom_sheet().get_all_values()[1:] # Gives data in list of list format, skipping the header row elif clo.startswith("cust_"): print "starts with cust_" data = get_custom_sheet(clo).get_all_values()[1:] else: print "Different: " + clo cu = db.cursor() cu.execute(QUERRY['other'], campaign) for x in cu: data.append(x) blocked_set = get_block_set() data = map( lambda k: [str(k[0]).strip('+ ').replace('-', '')] + list(k[1:]), [x for x in data if len(x) >= 2] ) data = [a for a in data if ','.join(a[0:2]) not in blocked_set] return data
def work_external_data(event): try: oid = event['oid'] url = 'http://45.55.72.208/wadi/query?id=' + str(oid) r = requests.get(url) print "Inside work external" if r.status_code == 200: rdata = r.json() filename = "res_" + str(event['id']) + ".csv" filename_full = './data/temp/' + filename if 'query' in rdata: query = rdata['query'] cursor = db.cursor() cursor.execute(query) print "Got query" + query save_to_file(cursor, filename_full, ['Phone', 'Language']) elif 'pipeline' in rdata and 'options' in rdata: res, headers = execute_pipeline(rdata['pipeline'], rdata['options']) update_job_status(oid, customer_count=len( res)) # Notify the API about the total number of customers save_to_file(res, filename_full, headers) else: raise Exception print "Updating action" upload_file(filename, filename_full) if event.get('repeat', 'Once') == 'No Send': action = 'Done' else: action = 'Data Loaded' updateAction(event['id'], action, oid=oid) print "Updating link" updateLink(event['id'], 'http://jlabs.co/downloadcsv.php?file=' + filename, oid=oid) return True else: updateAction(event['id'], 'Bad Link', oid=oid) return False except Exception: cLogger.exception("crashed with event %s", str(event)) return False
def work_external_data(event): try: oid = event['oid'] url = 'http://45.55.72.208/wadi/query?id='+str(oid) r = requests.get(url) print "Inside work external" if r.status_code == 200: rdata = r.json() filename = "res_"+str(event['id'])+".csv" filename_full = './data/temp/'+filename if 'query' in rdata: query = rdata['query'] cursor = db.cursor() cursor.execute(query) print "Got query"+query save_to_file(cursor, filename_full, ['Phone', 'Language']) elif 'pipeline' in rdata and 'options' in rdata: res, headers = execute_pipeline(rdata['pipeline'], rdata['options']) update_job_status(oid, customer_count=len(res)) # Notify the API about the total number of customers save_to_file(res, filename_full, headers) else: raise Exception print "Updating action" upload_file(filename, filename_full) if event.get('repeat', 'Once') == 'No Send': action = 'Done' else: action = 'Data Loaded' updateAction(event['id'], action, oid=oid) print "Updating link" updateLink(event['id'], 'http://jlabs.co/downloadcsv.php?file='+filename, oid=oid) return True else: updateAction(event['id'], 'Bad Link', oid=oid) return False except Exception: cLogger.exception("crashed with event %s", str(event)) return False
def work_external_data(event): try: url = event['External Link'] r = requests.get(url) print "Inside work external" if r.status_code == 200: rdata = r.json() filename = "res_"+str(event['ID'])+".csv" filename_full = './data/temp/'+filename if 'query' in rdata: query = rdata['query'] cursor = db.cursor() cursor.execute(query) print "Got query"+query save_to_file(cursor, filename_full, ['Phone', 'Language']) elif 'pipeline' in rdata and 'options' in rdata: res, headers = execute_pipeline(rdata['pipeline'], rdata['options']) save_to_file(res, filename_full, headers) else: print "Error" return print "Updating action" upload_file(filename, filename_full) updateAction(event['ID'], 'Data Loaded') print "Updating link" updateLink(event['ID'], 'http://jlabs.co/downloadcsv.php?file='+filename) return True else: updateAction(event['ID'], 'Bad Link') return False except Exception: cLogger.exception("crashed with event %s", str(event)) return False