def batch_search_view(): arg_hash = request.args.getlist('md5') hash_list = parse_hash_list(list_to_string(arg_hash)) if hash_list: found = batch_search_hash(hash_list) if found: return jsonify(results=found), 200 # return json.dumps(found) # return jsonify(json.dumps(found)) else: return jsonify(dict(error='Not a valid API end point.', response=404)), 404 else: return jsonify(dict(error='Missing Parameters', response=400)), 400
def batch_query_virustotal(new_hash_list): data = {} #: Break list into 25 unit chuncks for VirusTotal vt_batch_hash_list = list(split_seq(new_hash_list, 25)) for twentyfive_hashes in vt_batch_hash_list: response = vt.get_file_report(list_to_string(twentyfive_hashes)) if hasattr(response, 'error'): flash(response['error']) else: vt_results = response['results'] for result in vt_results: if result['response_code']: # print "Evilness: %d" % result['positives'] data['md5'] = result['md5'].upper() else: data['md5'] = result['resource'].upper() result['timestamp'] = r.now() # datetime.utcnow() data['VirusTotal'] = result db_insert(data) data.clear()