-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
98 lines (73 loc) · 2.7 KB
/
Copy pathmain.py
File metadata and controls
98 lines (73 loc) · 2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/python
# -*- coding: utf-8 -*-
from flask import Flask, render_template, request
import sqlite3 as sql
import csv
app = Flask(__name__)
import shutil
import sqlite3
import os
conn = sqlite3.connect('UserDB.db')
# print("Opened database successfully")
# conn.execute('CREATE TABLE students (name TEXT, addr TEXT, city TEXT, pin TEXT)')
# print("Table created successfully")
# conn.close()
@app.route('/')
def home():
return render_template('Home.html')
# @app.route('/enternew')
# def new_student():
# return render_template('student.html')
@app.route('/addrec', methods=['POST', 'GET'])
def addrec():
if request.method == 'POST':
try:
# File = request.form['CSV']
my_path = os.path.abspath(os.path.dirname(__file__))
path = os.path.join(my_path, '/orig/people.csv')
with open(path, 'r') as f:
dr = csv.DictReader(f) # comma is default delimiter................
to_db = [(
i['Name'],
i['Vehicle'],
i['Grade'],
i['Room'],
i['Telnum'],
i['Picture'],
i['Keywords'],
) for i in dr]
with sql.connect('UserDB.db') as con:
cur = con.cursor()
cur.executemany('INSERT INTO userdata (name,grade,room,telnum,picture,keyboard,vehicle) VALUES (?,?,?,?,?,?,?)'
, to_db)
con.commit()
except:
con.rollback()
# msg = 'error in insert operation'
finally:
# return render_template('Message.html', msg=msg)
con.close()
@app.route('/Swap')
def Swap():
src = \
'E:\\Hemil\\UTA\\Study\\Summer 2018\\First5Week\\CloudComputing\\Assignments\\Practice\\Quiz\\hemil2\\orig\\'
dst = \
'E:\\Hemil\\UTA\\Study\\Summer 2018\\First5Week\\CloudComputing\\Assignments\\Practice\\Quiz\\hemil2\\dups\\'
files = os.listdir(src)
for f in files:
shutil.move(src + f, dst)
msg = 'Swapped From Original to duplicate'
return render_template('Message.html', msg=msg)
@app.route('/SwapBack')
def SwapBack():
dst = \
'E:\\Hemil\\UTA\\Study\\Summer 2018\\First5Week\\CloudComputing\\Assignments\\Practice\\Quiz\\hemil2\\orig\\'
src = \
'E:\\Hemil\\UTA\\Study\\Summer 2018\\First5Week\\CloudComputing\\Assignments\\Practice\\Quiz\\hemil2\\dups\\'
files = os.listdir(src)
for f in files:
shutil.move(src + f, dst)
msg = 'Swapped From Duplicate to Original'
return render_template('Message.html', msg=msg)
if __name__ == '__main__':
app.run(debug=True)