Skip to content
Snippets Groups Projects
Commit 97222475 authored by m3-shakeel's avatar m3-shakeel
Browse files

Merge branch 'farhan_upload_csv' into 'main'

main with csv

See merge request !1
parents c14ffcde 2ae58958
Branches
No related tags found
1 merge request!1main with csv
const submitButton = document.querySelector("#submit-button"); const uploadForm = document.getElementById('uploadForm');
const firstNameInput = document.querySelector("#first-name"); const csvFile = document.getElementById('csvFile');
const lastNameInput = document.querySelector("#last-name"); const csvDataDiv = document.getElementById('csvData');
submitButton.addEventListener("click", () => { uploadForm.addEventListener('submit', async function(e) {
const firstName = firstNameInput.value; e.preventDefault();
const lastName = lastNameInput.value;
axios.post("http://127.0.0.1:5000", { firstName, lastName }).then(response => { const formData = new FormData();
document.querySelector("h1").innerHTML = response.data.fullName; formData.append('csvFile', csvFile.files[0]);
try {
const response = await axios.post('http://127.0.0.1:5000/upload', formData, {
headers: {
'Content-Type': 'multipart/form-data'
}
}); });
// Display the CSV data in the csvDataDiv
csvDataDiv.innerHTML = response.data;
} catch (error) {
console.error(error);
}
}); });
\ No newline at end of file
from flask import Flask, request, jsonify # from flask import Flask, render_template, request
# import csv
app = Flask(__name__) import pyodbc
@app.route("/", methods=["POST"]) # app = Flask(__name__)
def full_name():
data = request.get_json()
first_name = data.get("firstName")
last_name = data.get("lastName")
full_name = f"{first_name}"
return jsonify({"fullName": full_name})
if __name__ == "__main__": with pyodbc.connect(
app.run() Trusted_Connection='No',
Server='uwe-sdgp.database.windows.net,1433',
User='fi_developer',
Password='Eggyweggy156',
Database='feeding_inc') as conn:
with conn.cursor() as cursor:
cursor.execute("SELECT * FROM fid_patients")
row = cursor.fetchone()
while row:
print (str(row[0]) + " " + str(row[1]))
row = cursor.fetchone()
# @app.route('/')
# def index():
# return render_template('index.html')
# @app.route('/upload', methods=['POST'])
# def upload():
# csv_file = request.files['csvFile']
# if csv_file:
# csv_data = csv_file.stream.read().decode('utf-8')
# csv_rows = csv_data.split('\n')
# csv_table = '<table>'
# for row in csv_rows:
# csv_table += '<tr>'
# csv_cols = row.split(',')
# for col in csv_cols:
# csv_table += f'<td>{col}</td>'
# csv_table += '</tr>'
# csv_table += '</table>'
# return csv_table
# return 'Error: No CSV file provided'
# if __name__ == '__main__':
# app.run(debug=True)
\ No newline at end of file
...@@ -4,13 +4,20 @@ ...@@ -4,13 +4,20 @@
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<title>Hello World!</title> <title>Hello World!</title>
<link rel="stylesheet" href="index.css" /> <link rel="stylesheet" href="index.css" />
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
</head> </head>
<body> <body>
<p>Welcome to your Electron application! <h1></h1></p> <p>Welcome to your Electron application! <h1></h1></p>
<input type="text" id="first-name">
<input type="text" id="last-name"> <h1>CSV Viewer</h1>
<button id="submit-button">Submit</button> <form id="uploadForm" enctype="multipart/form-data">
<script src="https://unpkg.com/axios/dist/axios.min.js"></script> <input type="file" id="csvFile" name="csvFile">
<button type="submit">Upload</button>
</form>
<div id="csvData"></div>
<script src="app.js"></script> <script src="app.js"></script>
</body> </body>
</html> </html>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment