Skip to content

Commit

Permalink
commit changes
Browse files Browse the repository at this point in the history
  • Loading branch information
snehas-05 committed Oct 22, 2024
1 parent f89adeb commit 9c46cb0
Show file tree
Hide file tree
Showing 6 changed files with 229 additions and 0 deletions.
52 changes: 52 additions & 0 deletions 5star_review_system/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
from flask import Flask, render_template, request, jsonify
import mysql.connector
from datetime import datetime

app = Flask(__name__)

# MySQL configuration
db_config = {
'host': 'localhost',
'user': 'root',
'password': 'password',
'database': 'dataverse'
}

def get_db_connection():
conn = mysql.connector.connect(**db_config)
return conn

@app.route('/')
def index():
# Fetch reviews from the database
conn = get_db_connection()
cursor = conn.cursor(dictionary=True)
cursor.execute('SELECT * FROM reviews ORDER BY timestamp DESC')
reviews = cursor.fetchall()
conn.close()

return render_template('index.html', reviews=reviews)

@app.route('/submit-review', methods=['POST'])
def submit_review():
data = request.get_json()

name = data['name']
email = data['email']
rating = int(data['rating'])
review_text = data['review']
timestamp = datetime.now()

conn = get_db_connection()
cursor = conn.cursor()
cursor.execute(
'INSERT INTO reviews (name, email, rating, review, timestamp) VALUES (%s, %s, %s, %s, %s)',
(name, email, rating, review_text, timestamp)
)
conn.commit()
conn.close()

return jsonify({'success': True})

if __name__ == '__main__':
app.run(debug=True)
12 changes: 12 additions & 0 deletions 5star_review_system/db_config.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
CREATE DATABASE IF NOT EXISTS dataverse;

USE dataverse;

CREATE TABLE IF NOT EXISTS reviews (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255),
email VARCHAR(255),
rating INT,
review TEXT,
timestamp DATETIME
);
2 changes: 2 additions & 0 deletions 5star_review_system/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Flask==2.0.2
mysql-connector-python==8.0.26
33 changes: 33 additions & 0 deletions 5star_review_system/satic/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const form = document.getElementById('ratingForm');

form.addEventListener('submit', async function (event) {
event.preventDefault();

const formData = new FormData(form);
const data = {
name: formData.get('name'),
email: formData.get('email'),
rating: formData.get('rating'),
review: formData.get('review')
};

const response = await fetch('/submit-review', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(data),
});

const result = await response.json();

const messageElement = document.getElementById('responseMessage');
if (result.success) {
messageElement.textContent = "Thank you for your review!";
messageElement.style.color = 'green';
form.reset();
} else {
messageElement.textContent = "There was an error submitting your review.";
messageElement.style.color = 'red';
}
});
68 changes: 68 additions & 0 deletions 5star_review_system/satic/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
body {
font-family: Arial, sans-serif;
background-color: #f9f9f9;
color: #333;
}

.container {
max-width: 700px;
margin: 0 auto;
padding: 20px;
background-color: white;
box-shadow: 0 0 15px rgba(0, 0, 0, 0.1);
}

h1, h2 {
text-align: center;
}

form {
margin-bottom: 40px;
}

label {
font-weight: bold;
}

input, textarea, button {
width: 100%;
margin-bottom: 15px;
padding: 10px;
border: 1px solid #ccc;
border-radius: 5px;
}

.rating {
display: flex;
justify-content: center;
margin-bottom: 15px;
}

.rating input {
display: none;
}

.rating label {
font-size: 2rem;
color: #ddd;
cursor: pointer;
}

.rating input:checked ~ label {
color: #f7c41c;
}

button {
background-color: #4CAF50;
color: white;
border: none;
cursor: pointer;
}

.review {
margin-bottom: 20px;
}

.review p {
margin: 5px 0;
}
62 changes: 62 additions & 0 deletions 5star_review_system/templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dataset Rating and Reviews</title>
<link rel="stylesheet" href="/static/styles.css">
</head>
<body>

<div class="container">
<h1>Rate Dataverse</h1>

<form id="ratingForm" action="/submit-review" method="POST">
<label for="name">Your Name:</label>
<input type="text" id="name" name="name" required>

<label for="email">Your Email:</label>
<input type="email" id="email" name="email" required>

<label>Your Rating:</label>
<div class="rating">
<input type="radio" name="rating" id="star5" value="5">
<label for="star5"></label>
<input type="radio" name="rating" id="star4" value="4">
<label for="star4"></label>
<input type="radio" name="rating" id="star3" value="3">
<label for="star3"></label>
<input type="radio" name="rating" id="star2" value="2">
<label for="star2"></label>
<input type="radio" name="rating" id="star1" value="1">
<label for="star1"></label>
</div>

<label for="review">Your Review:</label>
<textarea id="review" name="review" rows="4" required></textarea>

<button type="submit">Submit Review</button>
</form>

<div id="responseMessage"></div>

<hr>

<h2>Recent Reviews</h2>
<div id="reviews">
{% for review in reviews %}
<div class="review">
<p><strong>{{ review.name }}</strong> rated <strong>{{ review.rating }}</strong>/5</p>
<p>{{ review.review }}</p>
<p><em>Submitted on: {{ review.timestamp }}</em></p>
</div>
<hr>
{% endfor %}
</div>

</div>

<script> src="/static/app.js"></script>

</body>
</html>

0 comments on commit 9c46cb0

Please sign in to comment.