Use drivers.csv for testing https://github.com/noikedan/flask_app/tree/develop
http://54.199.145.235/
Convert the Insert creation tool made with Python to the Web. Reason: It is difficult to use with the current one.
I'm making a web service for portfolio creation at home Those who want to use Insert Creation conveniently as a tool for data creation.
People who think that it is 0 if it can not be used in the field. A person who comes to the developer by saying a review or a customer. A person who comes impulsively every day saying only progress. People who only make complaints.
https://github.com/noikedan/INSERTSQL/tree/master/pythonInsrtSql
-Upload the file. -Create SQL. -Write to a file. -Download the file.
FLASK The SQL statement assumes postgresql.
The file upload method will follow the address below. https://flask.palletsprojects.com/en/1.1.x/quickstart/
https://github.com/noikedan/flask_app/tree/develop
Index.html
<html>
<head>
<tilte>Insert statement creation tool</tilte>
</head>
<body>
<form method="post" action="/todos/uploader" enctype = "multipart/form-data">
<input type="file" name="file" />
<input type="submit" value="Create" />
</form>
<p>
<a href="{{ url_for('.download_file') }}">Download</a>
</p>
</body>
</html>
InsertApp.py
from flask import Flask, render_template
from flask import request,send_file
app = Flask(__name__)
@app.route('/todos/uploader', methods=['GET', 'POST'])
def upload_file():
if request.method == 'POST':
f = request.files['file']
f.save(f.filename)
input = './' + f.filename
output = './output.txt'
table = input.split('/')[-1].split('.')[0]
with open(input, encoding='utf-8') as f:
with open(output, 'w', encoding='utf-8') as g:
contents = "Insert into " + table + "("
i = 0
for row in f:
if i == 0:
typeList = row.rstrip().split(',')
if i == 1:
columList = row.rstrip().split(',')
k = 0
for c in columList:
if len(columList) == k + 1:
contents = contents + c + 'VALUES ('
else:
contents = contents + c + ','
k = k + 1
basecontets = contents
if i >= 2:
j = 0
for r in row.rstrip().split(','):
if not 'INTEGER' in typeList[j]:
r = "'" + r + "'"
if len(row.rstrip().split(',')) == j + 1:
basecontets = basecontets + r
else:
basecontets = basecontets + r + ','
j = j + 1
basecontets = basecontets + ');' + '\n'
g.write(basecontets)
basecontets = contents
i = i + 1
print("Creation completed")
return render_template('index.html')
@app.route('/download')
def download_file():
path = './output.txt'
return send_file(path, as_attachment=True)
@app.route('/')
def index():
return render_template('index.html')
Recommended Posts