Skip to content

Update app.py #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 46 additions & 5 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,55 @@
from flask import Flask
from flask import Flask, request, jsonify
import os
import mysql.connector

app = Flask(__name__)

@app.route('/')
def hello():
return "Hello World!"
def connect_to_mysql():
# Get the database connection details from environment variables
db_host = os.getenv('DB_HOST') or 'mysql-container' # Replace 'mysql-container' with the actual container name
db_user = os.getenv('DB_USER') or 'root' # Replace 'root' with the actual database user
db_password = os.getenv('DB_PASSWORD') or 'password' # Replace 'password' with the actual database password
db_name = os.getenv('DB_NAME') or 'your_database' # Replace 'your_database' with the actual database name

print("Connecting to the database with URL:", db_host)

try:
print(f"Connecting to the database at {db_host}...")
return mysql.connector.connect(
host=db_host,
user=db_user,
password=db_password,
database=db_name
)
except mysql.connector.Error as err:
print(f"Error: {err}")
raise # Propagate the exception

def create_appointment_table(table_name, connection):
cursor = connection.cursor()
create_table_query = f"""
CREATE TABLE IF NOT EXISTS {table_name} (
id INT AUTO_INCREMENT PRIMARY KEY,
doctor_username VARCHAR(255),
patient_username VARCHAR(255),
day_of_week VARCHAR(255),
time_slot VARCHAR(255)
)
"""
cursor.execute(create_table_query)
connection.commit()

# ... (Rest of your code)

if __name__ == '__main__':
port = os.environ.get('FLASK_PORT') or 8080
port = int(port)

app.run(port=port,host='0.0.0.0')
# Connect to the MySQL database
db_connection = connect_to_mysql()

# Create the appointment table if it does not exist
create_appointment_table('appointments', db_connection)

# Run the Flask app
app.run(port=port, host='0.0.0.0')