Initial commit
This commit is contained in:
42
app.py
Normal file
42
app.py
Normal file
@@ -0,0 +1,42 @@
|
||||
from flask import Flask, render_template, request, send_file
|
||||
import pandas as pd
|
||||
from compare_gst_excel import find_unmatched_rows
|
||||
import os
|
||||
from werkzeug.utils import secure_filename
|
||||
|
||||
app = Flask(__name__)
|
||||
UPLOAD_FOLDER = 'uploads'
|
||||
RESULT_FILE = 'unmatched_result.xlsx'
|
||||
|
||||
if not os.path.exists(UPLOAD_FOLDER):
|
||||
os.makedirs(UPLOAD_FOLDER)
|
||||
|
||||
@app.route('/')
|
||||
def index():
|
||||
return render_template('upload.html')
|
||||
|
||||
@app.route('/upload', methods=['POST'])
|
||||
def upload_file():
|
||||
file = request.files['excel_file']
|
||||
if not file:
|
||||
return "No file uploaded.", 400
|
||||
|
||||
filename = secure_filename(file.filename)
|
||||
filepath = os.path.join(UPLOAD_FOLDER, filename)
|
||||
file.save(filepath)
|
||||
|
||||
try:
|
||||
# Read Excel with header in row 8 (0-indexed), so header=7
|
||||
df1 = pd.read_excel(filepath, sheet_name=0, header=7)
|
||||
df2 = pd.read_excel(filepath, sheet_name=1, header=7)
|
||||
|
||||
unmatched = find_unmatched_rows(df1, df2)
|
||||
unmatched.to_excel(RESULT_FILE, index=False)
|
||||
|
||||
return send_file(RESULT_FILE, as_attachment=True)
|
||||
|
||||
except Exception as e:
|
||||
return f"Error processing file: {e}", 500
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(host='0.0.0.0', port=5000,debug=True)
|
||||
Reference in New Issue
Block a user