def result(): if request.method == 'GET': form = ContactForm(request.args) if form.validate(): query = [] if form.email: query.append(('email', form.email.data)) if form.phone: query.append(('phone', form.phone.data.replace('+',''))) if form.twitter: query.append(('twitter', form.twitter.data)) if form.facebook: query.append(('facebookUsername', form.facebook.data)) userdata = aggregate_data(query) return render_template('results/get_results.html', ud=userdata) elif request.method == 'POST': if request.files.get('file'): # get emails from file, if one was uploaded batch_data = emails_from_file(request.files.get('file')) else: batch_data = request.form.get('batch_data') if batch_data: batch_data = batch_data.replace('facebook', 'facebookUsername').split(',') for i in range(len(batch_data)): batch_data[i] = tuple(batch_data[i].split(':')) if batch_data: response = batch_lookup(batch_data, request.url_root + url_for('webhook')[1:]) else: response = ["Nothing to process"] return render_template('results/post_results.html', response=response)
def get_list(): """ Get a list of contact data sets (JSON) in POST message and return the aggregated results for each set. """ print 'RECEIVED', request.json.get('data') data_lists = request.json.get('data') userdata = [] for data_list in data_lists: userdata.append(aggregate_data(data_list).data_dict) if userdata: return simplejson.dumps(userdata, default=json_util.default) return '[]' # empty list
def main(): # have the webhook working by: # 1. python flask_fullcontact.py # 2. proxylocal 5000 --host fullcontact # in Flask, the address of the webhook can be determined by using # request.url_root and url_for function webhook = 'http://fullcontact.t.proxylocal.com/webhook/' # request lookup for emails, phone, twitter and facebook data_list = [ ('email', '*****@*****.**'), ('email', '*****@*****.**'), ('phone', '+48601941311'), ('twitter', 'stefanwojcik'), ('facebookUsername', 'wojcikstefan') ] batch_lookup(data_list, webhook, debug=True) # request lookup for emails from CSV file batch_lookup(emails_from_file(open('emails_test.csv')), webhook) # aggregate data from 2 emails, phone, twitter and facebook u = aggregate_data(data_list) print u.to_dict()
def api(): """ Return the aggregated result for data sent in GET request or send a request to Full Contact API for POST request. """ if request.method == 'POST': # request data from Full Contact API data_list = request.json.get('data') logs = batch_lookup(data_list, request.url_root + url_for('webhook')[1:]) return simplejson.dumps(logs) elif request.method == 'GET' and request.args.items(): data_list = request.args.items() # split the arguments of the same type (separated by comma in GET request) for i in range(len(data_list)): if len(data_list[i][1].split(',')) > 1: data_type = data_list[i][0] for data_value in data_list[i][1].split(','): data_list.append((data_type, data_value)) data_list.pop(i) # aggregate the results and return userdata = aggregate_data(data_list) if userdata: return simplejson.dumps(userdata.data_dict, default=json_util.default) return '{}' # empty dictionary