def download(spider_id=1): results = Property.query.filter_by(spider_id=spider_id) data = _get_csv_headers(spider_id) if results: for result in results: if spider_id == 1: data.append( (result.id, result.spider.name, result.location.strip(), result.unit_floor, result.building_age.strip(), result.gross_price, result.gross_area, result.gross_per_foot, result.net_price, result.net_area, result.net_per_foot)) elif spider_id == 2: data.append((result.id, result.spider.name, result.location.strip(), result.date, result.buildling, result.size, result.ft_price, result.op_type, result.price, result.data_source)) elif spider_id == 3: data.append( (result.id, result.spider.name, result.location.strip(), result.price, result.image_url, result.about_the_flatshare, result.who_lives_there, result.ideal_flatmates, result.description)) output = excel.make_response_from_array(data, 'csv') output.headers["Content-Disposition"] = "attachment; filename=export.csv" output.headers["Content-type"] = "text/csv" return output
def download(): """ Create file in csv format and downloaded to user's computer""" db_connection = DbConnect(current_app.config) query = session['query'] time_title = '' if query.get("analysis_type") == "Daily": time_title = "Date" elif query.get("analysis_type") == "Monthly": time_title = "Month, Year" elif query.get("analysis_type") == "Yearly": time_title = "Year" else: time_title = "Timestamp" header = [ ("Output type", "District", "Site", "Reef", "Reef Location", "Depth"), [ query["output_type"], query["biomimic_type"], query["country"], query["state_province"], query["location"], query["zone"] ], (time_title, "Temperature") ] query_results = header + db_connection.get_query_raw_results( session['db_query']) db_connection.close() return excel.make_response_from_array(query_results, "csv", file_name="export_data")
def download_campaigns(): campaigns = Campaign.query.order_by(Campaign.created_at.desc()).all() campaigns_data = map(lambda x:x.campaign_details(),campaigns) header = ['Title','End Date','Remaining Days','Number of Donors','Target amount','Books', 'LIC', 'Percentage', 'Funds Raised','Status','Name','Organization Email_Id', 'Organization Phone Numbers','Person Email_Id','Person Phone Number','Language', 'Children'] campaigns_data.insert(0,header) return excel.make_response_from_array(campaigns_data, "xls")
def download_donations(): donations = Donation.query.all() donations_data = map(lambda x:x.donation_details(),donations) header = ["Donor Name"," Donor City","Donor State","Donor Address","Identification_Type","Identification","Donor Email", "Date", "Campaign Title", "Amount Donated", "Anonymous Donor", "80 G Cert Requested", "Confirmation Number"] donations_data.insert(0,header) return excel.make_response_from_array(donations_data, "xls")
def export_csv(): kroglist = requests.get(backend_url + '/export/csv').json() data = [ ['id', 'namn', 'adress', 'oppet_tider', 'bar_typ', 'stadsdel', 'beskrivning', 'betyg', 'hemside_lank', 'intrade', 'iframe_lank', 'approved'] ] for krog in kroglist: print(krog) data.append([ krog['id'], krog['namn'], krog['adress'], krog['oppet_tider'], krog['bar_typ'], krog['stadsdel'], krog['beskrivning'], krog['betyg'], krog['hemside_lank'], krog['intrade'], krog['iframe_lank'], krog['approved'] ]) response = excel.make_response_from_array(data, 'csv') response.headers["Content-Disposition"] = "attachment; filename=export.csv" response.headers["Content-type"] = "text/csv" return response
def get(self): cur = db.connection.cursor() cur.execute("""select title, FROM_UNIXTIME(start, '%Y-%m-%d--%T' ), FROM_UNIXTIME(end, '%Y-%m-%d--%T' ) from subscribe_calendar where month(FROM_UNIXTIME(start, '%Y-%m-%d--%T' )) < month(localtime())""") info = cur.fetchall() return excel.make_response_from_array(info, "csv")
def summary_download(facility_name, table_name): page_form = 'summary' add_row_id = False allow_links = False tqc = TableQueryCollection(table_name) tqc.get_results() tqc.format_results(add_row_id, allow_links) tq = tqc.get_first() csv = excel.make_response_from_array(tq.get_list_of_list(), 'csv') return csv
def download(): result = [['Event','Date','Techs']] for opp in Opps.query.all(): item = [opp.name, opp.date] for usr in opp.users: item.append(usr.fname +' '+ usr.lname) result.append(item) result = excel.make_response_from_array(result, 'csv', status=200, file_name='opps') response = make_response(result) response.headers["Content-Disposition"] = "attachment; filename=opps.csv" return response
def upload_array(struct_type): if struct_type == "array": array = request.get_array(field_name='file') return excel.make_response_from_array(array, 'xls') elif struct_type == "dict": adict = request.get_dict(field_name='file') return excel.make_response_from_dict(adict, 'xls') elif struct_type == "records": records = request.get_records(field_name='file') return excel.make_response_from_records(records, 'xls') elif struct_type == "book": book = request.get_book(field_name='file') return excel.make_response(book, 'xls') elif struct_type == "book_dict": book_dict = request.get_book_dict(field_name='file') return excel.make_response_from_book_dict(book_dict, 'xls')
def download(): """Function which helps to export the bookmarks list.""" if request.method == 'POST': c, conn = connection() c.execute("SELECT uid FROM users WHERE username = (%s)", session['username']) data = c.execute("SELECT * FROM bookmarks WHERE uid = (%s)", c.fetchone()[0]) # fetching bookmarks for logged in user data = (tuple(a[1:-1] for a in c.fetchall())) # truncating data from list heading = ((('Title', 'URL', 'Timestamp'),)) # adding heading for excel file output = excel.make_response_from_array(heading + data, 'csv') # converting list into csv output.headers["Content-Disposition"] = "attachment; \ filename=export.csv" output.headers["Content-type"] = "text/csv" # setting header to download the file return output
def combinationhitlist(): form = CombinationHitlist() if form.validate_on_submit(): hitlist_store1 = (form.data['hitlist']) #split out the data into a list hitlist_list1 = hitlist_store1.split('\r\n') db_hitlist1 = [] for x in hitlist_list1: #iterate through the list and search the db try: query_line_fromhitlist = CompoundDB.query.filter_by(formatted_batch_id=x).first() listio = (query_line_fromhitlist.formatted_batch_id, query_line_fromhitlist.barcode, query_line_fromhitlist.well_ref, query_line_fromhitlist.starting_concentration, query_line_fromhitlist.concentration_range) db_hitlist1.append(listio) except: flash('didnt work - '+ x) #second hitlist hitlist_store2 = (form.data['hitlist2']) #split out the data into a list hitlist_list2 = hitlist_store2.split('\r\n') db_hitlist2 = [] for x in hitlist_list2: #iterate through the list and search the db try: query_line_fromhitlist = CompoundDB.query.filter_by(formatted_batch_id=x).first() listio = (query_line_fromhitlist.formatted_batch_id, query_line_fromhitlist.barcode, query_line_fromhitlist.well_ref, query_line_fromhitlist.starting_concentration, query_line_fromhitlist.concentration_range) db_hitlist2.append(listio) except: flash('didnt work - '+ x) output_list = combination_make_hitlist(db_hitlist1, db_hitlist2, form.data['copies'], form.data['name']) output = excel.make_response_from_array(output_list, 'xls') output.headers["Content-Disposition"] = "attachment; filename=" + form.name.data + ".xls" output.headers["Content-type"] = "text/csv" flash("Done! ") return output return render_template('combination_hitlist.html', form=form)
def download(): """ Create file in csv format and downloaded to user's computer""" db_connection = DbConnect(current_app.config) query = session['query'] time_title = '' if query.get("analysis_type") == "Daily": time_title = "Date" elif query.get("analysis_type") == "Monthly": time_title = "Month, Year" elif query.get("analysis_type") == "Yearly": time_title = "Year" else: time_title = "Timestamp" header = [[key + ":" + str(value) for key, value in query.items()], (time_title, "Temperature")] query_results = header + db_connection.get_query_raw_results(session['db_query']) db_connection.close() return excel.make_response_from_array(query_results, "csv", file_name="export_data")
def download(): """ Create file in csv format and downloaded to user's computer""" db_connection = DbConnect(current_app.config) query = session['query'] time_title = '' if query.get("analysis_type") == "Daily": time_title = "Date" elif query.get("analysis_type") == "Monthly": time_title = "Month, Year" elif query.get("analysis_type") == "Yearly": time_title = "Year" else: time_title = "Timestamp" header = [[key + ":" + str(value) for key, value in query.items()], (time_title, "Temperature")] query_results = header + db_connection.get_query_raw_results( session['db_query']) db_connection.close() return excel.make_response_from_array(query_results, "csv", file_name="export_data")
def run(self): exam_results = ExamResult.query.filter_by( training_exam_id=self.training_exam.id) data = list() data.append(self.TITLES) for result in exam_results: datum = [] datum.extend(ExportExamResults.get_exam(result.training_exam_id)) datum.extend(ExportExamResults.get_trainee(result.trainee_id)) datum.extend(ExportExamResults.get_question(result.question_id)) datum.append(result.answer) datum.append(result.choice_id) datum.append('wrong' if result.question_score == 0 else 'correct') datum.append(result.question_score) data.append(datum) output = excel.make_response_from_array(data, 'csv') output.headers[ "Content-Disposition"] = "attachment; filename={}-{}-results.csv".format( self.training.training_name, self.training_exam.exam.title) output.headers["Content-type"] = "text/csv" return output
def download_file(): return excel.make_response_from_array([[1, 2], [3, 4]], "csv")
def vmassets_export(): exc_res = Action().data_export(cur='vmassets') # 调用api返回生成excel值 return excel.make_response_from_array(exc_res, "xlsx", file_name="export_vmassets")
def user_export(): exc_res = Action().data_export(cur='user') # 调用api返回生成excel值 return excel.make_response_from_array(exc_res, "xlsx", file_name="export_user")
def download_csv(): output = excel.make_response_from_array(get_process_list(), 'csv') output.headers['Content-type'] = 'text/csv' return output
def export_csv(): filename = "actual16-reboot" data = [['cpu', 'mem', 'hostname'], ['4', '8', 'monkey-hostname']] return excel.make_response_from_array(data, "csv", file_name=filename)
def hitlist(): form = Hitlist() if form.validate_on_submit(): hitlist_store = (form.data['hitlist']) #split out the data into a list hitlist_list = hitlist_store.split('\r\n') db_hitlist = [] for x in hitlist_list: #iterate through the list and search the db try: query_line_fromhitlist = CompoundDB.query.filter_by(formatted_batch_id=x).first() listio = (query_line_fromhitlist.formatted_batch_id, query_line_fromhitlist.barcode, query_line_fromhitlist.well_ref, query_line_fromhitlist.starting_concentration, query_line_fromhitlist.concentration_range) db_hitlist.append(listio) except: flash('didnt work - '+ x) output_list = make_hitlist(db_hitlist, form.data['copies'], form.data['name']) #the options are for 1=echo, just output the hitlist for echo if form.role.data == 1: output = excel.make_response_from_array(output_list, 'xls') output.headers["Content-Disposition"] = "attachment; filename=" + form.name.data + ".xls" output.headers["Content-type"] = "text/csv" else: #count the number of destination plates destination_barcodes = [] destination_barcodes_for_out = [] for x in output_list[1:]: destination_barcodes.append(x[5]) #have to have two columns for export, barcode means nothing destination_barcodes_for_out.append(x[5]) #make the barode list a set so it only has unique values destination_barcodes_for_out_set = list(set(destination_barcodes)) print(destination_barcodes_for_out_set) make_2dlist = [] for x in destination_barcodes_for_out_set: make_2dlist.append([x, "Barcode"]) destination_plates = (len(set(destination_barcodes))) #count the number of source plates source_barcodes = [] for x in output_list[1:]: source_barcodes.append(x[1]) source_plates = (len(set(source_barcodes))) output = excel.make_response_from_array(make_2dlist, 'xls') output.headers["Content-Disposition"] = "attachment; filename=" + form.name.data + "_barcodes.xls" output.headers["Content-type"] = "text/csv" if destination_plates + source_plates > 82: flash("WARNING, the number of plates exceed system capacity (82) for set " + form.name.data + ".") flash("Done! " + form.name.data) return output return render_template('pastehitlist.html', form=form)
def download(): """ flask view for download CSV """ output = excel.make_response_from_array(session['table'], 'csv') output.headers["Content-Disposition"] = "attachment; filename=export.csv" output.headers["Content-type"] = "text/csv" return output
def export_records(): return excel.make_response_from_array([[1,2], [3, 4]], "csv", file_name="export_data")
def download_file(): return excel.make_response_from_array([[1,2], [3, 4]], "csv")