-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtester.py
38 lines (31 loc) · 1.16 KB
/
tester.py
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
from flask import Flask, render_template, jsonify
import mysql.connector
import sql_connect as connect
app = Flask(__name__)
# Function to create an author
def create_author(name, nationality):
try:
sql = "INSERT INTO Author (Name, Nationality) VALUES (%s, %s)"
values = (name, nationality)
connect.cursor.execute(sql, values)
connect.db_connection.commit()
return jsonify({"message": "Author created successfully!"}), 200
except Exception as e:
return jsonify({"error": str(e)}), 500
# Function to read authors
def read_authors():
try:
connect.cursor.execute("SELECT * FROM Author")
authors = connect.cursor.fetchall()
return jsonify(authors), 200
except Exception as e:
return jsonify({"error": str(e)}), 500
# Define similar functions for other tables (e.g., publishers, publications, copyright agreements, etc.)
@app.route('/create_author/<name>/<nationality>')
def create_author_route(name, nationality):
return create_author(name, nationality)
@app.route('/read_authors')
def read_authors_route():
return read_authors()
if __name__ == "__main__":
app.run(debug=True)