def save_data(): try: reset_db_name(request.json['db_name']) records = request.json['table'] db = DBAccess(env.DB_NAME) name_ = trim_collection_name(request.json['name']) db.clear_collection(name_) db.save_to_db(name_, records) return jsonify(status=env.HTML_STATUS.OK) except Exception as e: logger.error("Cannot save data: %s" % e) return jsonify(status=env.HTML_STATUS.ERROR)
def JESA_UploadTable(name, table, db_name="mine2farm"): records = [] header = list(table) for row in table.iterrows(): record = {} for h in header: record[h] = row[1][h] records.append(record) env.DB_NAME = db_name db_access = DBAccess(env.DB_NAME) name_ = trim_collection_name(name) db_access.clear_collection(name_) db_access.save_to_db(name_, records) COLLECTIONS_CACHE.add(name_) return "%s Saved! @%s" % (name_, datetime.now().strftime("%H:%M:%S"))