def get_ads(): es = ElasticSearchManager() bf = BulkFolders() ad_id = request.args.get('uri') postids = request.args.get('post_ids') phone = request.args.get('phone') size = request.args.get('size') headings = request.args.get('heading') store = request.args.get('store') """first line columns names if headings = 1""" if headings is None: headings = '0' if size is None: size = "20" if headings == "1": result = "\t".join(bf.ht_headings) + '\n' else: result = '' if store is None: store = "1" try: if ad_id is not None: ids = [ad_id] result += process_results(bf, es.search_es(ElasticSearchManager.create_ids_query(ids), None)) if store == "1": response = make_response(result) response.headers["Content-Disposition"] = "attachment; filename=data.tsv" return response else: return Response(result, 200) except Exception as e: return Response(str(e), 500) try: if postids is not None: post_ids = postids.split(',') for post_id in post_ids: res = es.search_es(ElasticSearchManager.create_postid_query(post_id), int(size)) hits = res['hits']['hits'] for hit in hits: ad = hit['_source'] if post_id in ad['url']: tab_separated = "\t".join(bf.ht_to_array(ad)) result = result + tab_separated + '\n' if store == "1": response = make_response(result) response.headers["Content-Disposition"] = "attachment; filename=data.tsv" return response else: return Response(result, 200) except Exception as e: return Response(str(e), 500) try: if phone is not None: phones = [phone] result += process_results(bf, es.search_es( ElasticSearchManager.create_terms_query(phone_field, phones), int(size))) if store == "1": response = make_response(result) response.headers["Content-Disposition"] = "attachment; filename=data.tsv" return response else: return Response(result, 200) except Exception as e: return Response(str(e), 500)