コード例 #1
0
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
コード例 #2
0
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
コード例 #3
0
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