Category: projects

https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSMAVf-0MreWDi9XMI_A_h0luXpLCCnA-o5wA&s

  • Customer Relationship Management (CRM)

    Step 1: Set Up Your Environment

    1. Install Required Packages: Make sure you have Python installed, then set up a virtual environment and install Flask and SQLAlchemy.
    mkdir crm_app cd crm_app python -m venv venv source venv/bin/activate # On Windows use venv\Scripts\activate pip install Flask Flask-SQLAlchemy

    Step 2: Create the Database Model

    Create a file named app.py:

    from flask import Flask, request, jsonify
    from flask_sqlalchemy import SQLAlchemy
    
    app = Flask(__name__)
    app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///crm.db'
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
    db = SQLAlchemy(app)
    
    class Customer(db.Model):
    
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(100), nullable=False)
    email = db.Column(db.String(100), unique=True, nullable=False)
    phone = db.Column(db.String(20), nullable=True)
    def to_dict(self):
        return {"id": self.id, "name": self.name, "email": self.email, "phone": self.phone}
    with app.app_context():
    db.create_all()

    Step 3: Create API Endpoints

    Add the following code to app.py to create API endpoints for managing customers:

    @app.route('/customers', methods=['POST'])
    def add_customer():
    
    data = request.get_json()
    new_customer = Customer(name=data['name'], email=data['email'], phone=data.get('phone'))
    db.session.add(new_customer)
    db.session.commit()
    return jsonify(new_customer.to_dict()), 201
    @app.route('/customers', methods=['GET']) def get_customers():
    customers = Customer.query.all()
    return jsonify([customer.to_dict() for customer in customers])
    @app.route('/customers/<int:id>', methods=['GET']) def get_customer(id):
    customer = Customer.query.get_or_404(id)
    return jsonify(customer.to_dict())
    @app.route('/customers/<int:id>', methods=['PUT']) def update_customer(id):
    data = request.get_json()
    customer = Customer.query.get_or_404(id)
    customer.name = data&#91;'name']
    customer.email = data&#91;'email']
    customer.phone = data.get('phone')
    db.session.commit()
    return jsonify(customer.to_dict())
    @app.route('/customers/<int:id>', methods=['DELETE']) def delete_customer(id):
    customer = Customer.query.get_or_404(id)
    db.session.delete(customer)
    db.session.commit()
    return '', 204
    if __name__ == '__main__':
    app.run(debug=True)

    Step 4: Run the Application

    Run your Flask app:

    python app.py
    

    Step 5: Test the API

    You can test your API using tools like Postman or cURL. Here are some example requests:

    1. Add a Customer:
    curl -X POST http://127.0.0.1:5000/customers -H "Content-Type: application/json" -d '{"name": "John Doe", "email": "[email protected]", "phone": "123-456-7890"}'
    1. Get All Customers:
    curl http://127.0.0.1:5000/customers
    1. Get a Specific Customer:
    curl http://127.0.0.1:5000/customers/1
    1. Update a Customer:
    curl -X PUT http://127.0.0.1:5000/customers/1 -H "Content-Type: application/json" -d '{"name": "Jane Doe", "email": "[email protected]", "phone": "098-765-4321"}'
    1. Delete a Customer:
    curl -X DELETE http://127.0.0.1:5000/customers/1
  • Inventory Management System

    Inventory Management System (IMS)

    Requirements

    • Python 3.x
    • Basic knowledge of Python

    Code

    class Item:
    
    def __init__(self, name, quantity, price):
        self.name = name
        self.quantity = quantity
        self.price = price
    def __str__(self):
        return f"Item(name={self.name}, quantity={self.quantity}, price={self.price})"
    class Inventory:
    def __init__(self):
        self.items = {}
    def add_item(self, name, quantity, price):
        if name in self.items:
            self.items&#91;name].quantity += quantity
        else:
            self.items&#91;name] = Item(name, quantity, price)
        print(f"Added {quantity} of {name}.")
    def update_item(self, name, quantity=None, price=None):
        if name in self.items:
            if quantity is not None:
                self.items&#91;name].quantity = quantity
            if price is not None:
                self.items&#91;name].price = price
            print(f"Updated {name}.")
        else:
            print(f"Item {name} not found.")
    def delete_item(self, name):
        if name in self.items:
            del self.items&#91;name]
            print(f"Deleted {name}.")
        else:
            print(f"Item {name} not found.")
    def view_inventory(self):
        if not self.items:
            print("Inventory is empty.")
        else:
            for item in self.items.values():
                print(item)
    def main():
    inventory = Inventory()
    while True:
        print("\nInventory Management System")
        print("1. Add Item")
        print("2. Update Item")
        print("3. Delete Item")
        print("4. View Inventory")
        print("5. Exit")
        choice = input("Choose an option: ")
        if choice == '1':
            name = input("Enter item name: ")
            quantity = int(input("Enter quantity: "))
            price = float(input("Enter price: "))
            inventory.add_item(name, quantity, price)
        elif choice == '2':
            name = input("Enter item name: ")
            quantity = input("Enter new quantity (leave blank to skip): ")
            price = input("Enter new price (leave blank to skip): ")
            inventory.update_item(name, quantity=int(quantity) if quantity else None,
                                  price=float(price) if price else None)
        elif choice == '3':
            name = input("Enter item name: ")
            inventory.delete_item(name)
        elif choice == '4':
            inventory.view_inventory()
        elif choice == '5':
            print("Exiting...")
            break
        else:
            print("Invalid choice. Please try again.")
    if __name__ == "__main__":
    main()

    How It Works

    1. Classes:
      • Item: Represents an individual item with attributes for name, quantity, and price.
      • Inventory: Manages a collection of items, allowing you to add, update, delete, and view items.
    2. Functions:
      • add_item(): Adds a new item or updates the quantity if it already exists.
      • update_item(): Updates the quantity and/or price of an existing item.
      • delete_item(): Deletes an item from the inventory.
      • view_inventory(): Displays all items in the inventory.
    3. Main Loop: The main() function provides a simple console menu for user interaction.

    Running the Code

    1. Save the code to a file named inventory_management.py.
    2. Run the script using Python:
    python inventory_management.py
  • Fitness Tracker Application

    Step 1: Create the Flask Application

    app.py

    from flask import Flask, render_template, request, redirect, url_for
    import sqlite3
    
    app = Flask(__name__)
    
    def init_db():
    
    with sqlite3.connect("fitness_tracker.db") as conn:
        conn.execute('''
            CREATE TABLE IF NOT EXISTS workouts (
                id INTEGER PRIMARY KEY AUTOINCREMENT,
                date TEXT NOT NULL,
                type TEXT NOT NULL,
                duration INTEGER NOT NULL,
                calories INTEGER NOT NULL
            )
        ''')
    conn.close()
    @app.route('/') def index():
    return render_template('index.html')
    @app.route('/log', methods=['GET', 'POST']) def log():
    if request.method == 'POST':
        date = request.form&#91;'date']
        type_ = request.form&#91;'type']
        duration = request.form&#91;'duration']
        calories = request.form&#91;'calories']
        
        with sqlite3.connect("fitness_tracker.db") as conn:
            conn.execute('''
                INSERT INTO workouts (date, type, duration, calories)
                VALUES (?, ?, ?, ?)
            ''', (date, type_, duration, calories))
        
        return redirect(url_for('history'))
    return render_template('log.html')
    @app.route('/history') def history():
    with sqlite3.connect("fitness_tracker.db") as conn:
        cursor = conn.execute('SELECT * FROM workouts ORDER BY date DESC')
        workouts = cursor.fetchall()
    return render_template('history.html', workouts=workouts)
    if __name__ == '__main__':
    init_db()
    app.run(debug=True)

    Step 2: Create the HTML Templates

    templates/index.html

    <!DOCTYPE html>
    <html lang="en">
    <head>
    
    &lt;meta charset="UTF-8">
    &lt;title>Fitness Tracker&lt;/title>
    &lt;link rel="stylesheet" href="{{ url_for('static', filename='styles.css') }}">
    </head> <body>
    &lt;h1>Welcome to the Fitness Tracker&lt;/h1>
    &lt;a href="/log">Log a Workout&lt;/a>&lt;br>
    &lt;a href="/history">View Workout History&lt;/a>
    </body> </html>

    templates/log.html

    <!DOCTYPE html>
    <html lang="en">
    <head>
    
    &lt;meta charset="UTF-8">
    &lt;title>Log a Workout&lt;/title>
    &lt;link rel="stylesheet" href="{{ url_for('static', filename='styles.css') }}">
    </head> <body>
    &lt;h1>Log a Workout&lt;/h1>
    &lt;form method="post">
        &lt;label>Date:&lt;/label>&lt;br>
        &lt;input type="date" name="date" required>&lt;br>
        &lt;label>Type:&lt;/label>&lt;br>
        &lt;input type="text" name="type" required>&lt;br>
        &lt;label>Duration (in minutes):&lt;/label>&lt;br>
        &lt;input type="number" name="duration" required>&lt;br>
        &lt;label>Calories Burned:&lt;/label>&lt;br>
        &lt;input type="number" name="calories" required>&lt;br>
        &lt;button type="submit">Log Workout&lt;/button>
    &lt;/form>
    &lt;a href="/">Back to Home&lt;/a>
    </body> </html>

    templates/history.html

    <!DOCTYPE html>
    <html lang="en">
    <head>
    
    &lt;meta charset="UTF-8">
    &lt;title>Workout History&lt;/title>
    &lt;link rel="stylesheet" href="{{ url_for('static', filename='styles.css') }}">
    </head> <body>
    &lt;h1>Workout History&lt;/h1>
    &lt;table>
        &lt;tr>
            &lt;th>Date&lt;/th>
            &lt;th>Type&lt;/th>
            &lt;th>Duration (min)&lt;/th>
            &lt;th>Calories&lt;/th>
        &lt;/tr>
        {% for workout in workouts %}
        &lt;tr>
            &lt;td>{{ workout&#91;1] }}&lt;/td>
            &lt;td>{{ workout&#91;2] }}&lt;/td>
            &lt;td>{{ workout&#91;3] }}&lt;/td>
            &lt;td>{{ workout&#91;4] }}&lt;/td>
        &lt;/tr>
        {% endfor %}
    &lt;/table>
    &lt;a href="/">Back to Home&lt;/a>
    </body> </html>

    Step 3: Add Basic Styles

    static/styles.css

    body {
    
    font-family: Arial, sans-serif;
    margin: 20px;
    } h1 {
    color: #333;
    } table {
    width: 100%;
    border-collapse: collapse;
    } table, th, td {
    border: 1px solid #ddd;
    } th, td {
    padding: 8px;
    text-align: left;
    }

    Step 4: Run the Application

    1. Navigate to your project directory in the terminal.
    2. Run the application:
    python app.py
    1. Open your web browser and go to http://127.0.0.1:5000.
  • Recipe Sharing Community

    Step 1: Set Up Your Environment

    1. Install Flask: You can set up a virtual environment and install Flask.
    python -m venv venv source venv/bin/activate # On Windows use venv\Scripts\activate pip install Flask
    1. Project Structure:
    recipe_community/ ├── app.py ├── templates/ │ ├── index.html │ ├── add_recipe.html └── static/ └── style.css

    Step 2: Create the Backend (app.py)

    Here’s a simple Flask application to handle recipe submissions:

    from flask import Flask, render_template, request, redirect, url_for
    
    app = Flask(__name__)
    
    # In-memory storage for recipes (you can replace this with a database later)
    recipes = []
    
    @app.route('/')
    def index():
    
    return render_template('index.html', recipes=recipes)
    @app.route('/add', methods=['GET', 'POST']) def add_recipe():
    if request.method == 'POST':
        title = request.form&#91;'title']
        ingredients = request.form&#91;'ingredients']
        instructions = request.form&#91;'instructions']
        recipes.append({
            'title': title,
            'ingredients': ingredients.split(','),
            'instructions': instructions
        })
        return redirect(url_for('index'))
    return render_template('add_recipe.html')
    if __name__ == '__main__':
    app.run(debug=True)

    Step 3: Create the Frontend (HTML Templates)

    1. index.html (to display recipes):
    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}"> <title>Recipe Sharing Community</title> </head> <body> <h1>Recipe Sharing Community</h1> <a href="/add">Add a Recipe</a> <ul> {% for recipe in recipes %} <li> <h2>{{ recipe.title }}</h2> <h3>Ingredients:</h3> <ul> {% for ingredient in recipe.ingredients %} <li>{{ ingredient }}</li> {% endfor %} </ul> <h3>Instructions:</h3> <p>{{ recipe.instructions }}</p> </li> {% endfor %} </ul> </body> </html>
    1. add_recipe.html (to add new recipes):
    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}"> <title>Add Recipe</title> </head> <body> <h1>Add a New Recipe</h1> <form method="POST"> <label for="title">Recipe Title:</label><br> <input type="text" id="title" name="title" required><br> <label for="ingredients">Ingredients (comma-separated):</label><br> <input type="text" id="ingredients" name="ingredients" required><br> <label for="instructions">Instructions:</label><br> <textarea id="instructions" name="instructions" required></textarea><br> <button type="submit">Submit Recipe</button> </form> <a href="/">Back to Home</a> </body> </html>

    Step 4: Add Some Basic CSS (style.css)

    You can create a simple CSS file to style your application:

    body {
    
    font-family: Arial, sans-serif;
    margin: 20px;
    } h1, h2, h3 {
    color: #333;
    } ul {
    list-style-type: none;
    padding: 0;
    } form {
    margin-bottom: 20px;
    }

    Step 5: Run Your Application

    Now you can run your Flask app:

    python app.py
    
  • Event Management System

    You can install Flask using pip if you haven’t already:

    pip install Flask
    

    Project Structure

    event_management_system/
    
    ├── app.py
    ├── templates/
    │   ├── index.html
    │   ├── create_event.html
    │   └── event_details.html
    └── static/
        └── style.css

    Step 1: Setting Up Flask

    app.py

    This will be the main application file.

    from flask import Flask, render_template, request, redirect, url_for
    import sqlite3
    
    app = Flask(__name__)
    
    # Database setup
    def init_db():
    
    with sqlite3.connect("events.db") as conn:
        cursor = conn.cursor()
        cursor.execute('''
            CREATE TABLE IF NOT EXISTS events (
                id INTEGER PRIMARY KEY,
                name TEXT NOT NULL,
                description TEXT NOT NULL,
                date TEXT NOT NULL,
                location TEXT NOT NULL
            )
        ''')
        conn.commit()
    @app.route('/') def index():
    conn = sqlite3.connect("events.db")
    cursor = conn.cursor()
    cursor.execute("SELECT * FROM events")
    events = cursor.fetchall()
    conn.close()
    return render_template('index.html', events=events)
    @app.route('/event/<int:event_id>') def event_details(event_id):
    conn = sqlite3.connect("events.db")
    cursor = conn.cursor()
    cursor.execute("SELECT * FROM events WHERE id = ?", (event_id,))
    event = cursor.fetchone()
    conn.close()
    return render_template('event_details.html', event=event)
    @app.route('/create_event', methods=['GET', 'POST']) def create_event():
    if request.method == 'POST':
        name = request.form&#91;'name']
        description = request.form&#91;'description']
        date = request.form&#91;'date']
        location = request.form&#91;'location']
        
        conn = sqlite3.connect("events.db")
        cursor = conn.cursor()
        cursor.execute("INSERT INTO events (name, description, date, location) VALUES (?, ?, ?, ?)",
                       (name, description, date, location))
        conn.commit()
        conn.close()
        
        return redirect(url_for('index'))
    
    return render_template('create_event.html')
    if __name__ == '__main__':
    init_db()
    app.run(debug=True)

    Step 2: Creating HTML Templates

    templates/index.html

    This will display all events.

    <!DOCTYPE html>
    <html lang="en">
    <head>
    
    &lt;meta charset="UTF-8">
    &lt;meta name="viewport" content="width=device-width, initial-scale=1.0">
    &lt;link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
    &lt;title>Event Management System&lt;/title>
    </head> <body>
    &lt;h1>Events&lt;/h1>
    &lt;a href="{{ url_for('create_event') }}">Create New Event&lt;/a>
    &lt;ul>
        {% for event in events %}
            &lt;li>
                &lt;a href="{{ url_for('event_details', event_id=event&#91;0]) }}">{{ event&#91;1] }}&lt;/a> - {{ event&#91;3] }} @ {{ event&#91;4] }}
            &lt;/li>
        {% endfor %}
    &lt;/ul>
    </body> </html>

    templates/create_event.html

    This allows users to create new events.

    <!DOCTYPE html>
    <html lang="en">
    <head>
    
    &lt;meta charset="UTF-8">
    &lt;meta name="viewport" content="width=device-width, initial-scale=1.0">
    &lt;link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
    &lt;title>Create Event&lt;/title>
    </head> <body>
    &lt;h1>Create New Event&lt;/h1>
    &lt;form method="POST">
        &lt;label>Name: &lt;input type="text" name="name" required>&lt;/label>&lt;br>
        &lt;label>Description: &lt;textarea name="description" required>&lt;/textarea>&lt;/label>&lt;br>
        &lt;label>Date: &lt;input type="date" name="date" required>&lt;/label>&lt;br>
        &lt;label>Location: &lt;input type="text" name="location" required>&lt;/label>&lt;br>
        &lt;button type="submit">Create Event&lt;/button>
    &lt;/form>
    &lt;a href="{{ url_for('index') }}">Back to Events&lt;/a>
    </body> </html>

    templates/event_details.html

    This shows the details of a single event.

    <!DOCTYPE html>
    <html lang="en">
    <head>
    
    &lt;meta charset="UTF-8">
    &lt;meta name="viewport" content="width=device-width, initial-scale=1.0">
    &lt;link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
    &lt;title>{{ event&#91;1] }}&lt;/title>
    </head> <body>
    &lt;h1>{{ event&#91;1] }}&lt;/h1>
    &lt;p>{{ event&#91;2] }}&lt;/p>
    &lt;p>Date: {{ event&#91;3] }}&lt;/p>
    &lt;p>Location: {{ event&#91;4] }}&lt;/p>
    &lt;a href="{{ url_for('index') }}">Back to Events&lt;/a>
    </body> </html>

    Step 3: Add Some Styles

    static/style.css

    Add some basic styling.

    body {
    
    font-family: Arial, sans-serif;
    } h1 {
    color: #333;
    } ul {
    list-style-type: none;
    } li {
    margin: 10px 0;
    }

    Step 4: Run the Application

    Now you can run your application:

    bashCopy codepython app.py
    

    Visit http://127.0.0.1:5000 in your web browser, and you should see the Event Management System in action!

    Additional Features

    This is a basic example. You might want to extend this system with features like:

    • User authentication
    • Event registration
    • Notification system
    • Advanced search functionality

  • Real Estate Listing Website

    Project Structure

    real-estate-website/
    ├── server.js
    ├── package.json
    ├── public/
    │   ├── index.html
    │   ├── style.css
    │   └── script.js
    └── data/
    
    └── listings.json

    Step 1: Setup Node.js Server

    1. Initialize Node.js Project:
    mkdir real-estate-website cd real-estate-website npm init -y npm install express
    1. Create server.js:
    // server.js const express = require('express'); const fs = require('fs'); const path = require('path'); const app = express(); const PORT = process.env.PORT || 3000; app.use(express.static('public')); app.use(express.json()); // Endpoint to get listings app.get('/api/listings', (req, res) => { fs.readFile(path.join(__dirname, 'data', 'listings.json'), 'utf8', (err, data) => { if (err) { res.status(500).send('Error reading listings'); } else { res.json(JSON.parse(data)); } }); }); app.listen(PORT, () => { console.log(Server is running on http://localhost:${PORT}); });

    Step 2: Create Frontend

    1. Create index.html in public/:
    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Real Estate Listings</title> <link rel="stylesheet" href="style.css"> </head> <body> <h1>Real Estate Listings</h1> <div id="listings"></div> <script src="script.js"></script> </body> </html>
    1. Create style.css in public/:
    body { font-family: Arial, sans-serif; margin: 20px; } h1 { text-align: center; } #listings { display: flex; flex-wrap: wrap; justify-content: center; } .listing { border: 1px solid #ccc; margin: 10px; padding: 10px; width: 300px; }
    1. Create script.js in public/:
    // script.js fetch('/api/listings') .then(response => response.json()) .then(data => { const listingsDiv = document.getElementById('listings'); data.forEach(listing => { const listingDiv = document.createElement('div'); listingDiv.className = 'listing'; listingDiv.innerHTML =  &lt;h2>${listing.title}&lt;/h2> &lt;p>${listing.description}&lt;/p> &lt;p>Price: $${listing.price}&lt;/p> ; listingsDiv.appendChild(listingDiv); }); }) .catch(error => console.error('Error fetching listings:', error));

    Step 3: Create Listings Data

    1. Create listings.json in data/:
    [ { "title": "Beautiful Family Home", "description": "A spacious home with a beautiful garden.", "price": 350000 }, { "title": "Modern Apartment", "description": "A stylish apartment in the city center.", "price": 250000 }, { "title": "Cozy Cottage", "description": "A charming cottage in a quiet neighborhood.", "price": 180000 } ]

    Step 4: Run the Application

    1. Start the Server:bashCopy codenode server.js
    2. Access the Application:Open your browser and go to http://localhost:3000.
  • Online Learning Portal

    Directory Structure

    online_learning_portal/
    │
    ├── app.py
    ├── templates/
    │   ├── base.html
    │   ├── index.html
    │   └── course.html
    └── static/
    
    └── style.css

    1. Setting Up the Flask App

    app.py

    from flask import Flask, render_template, url_for, redirect
    
    app = Flask(__name__)
    
    # Sample data for courses
    courses = [
    
    {'id': 1, 'title': 'Python for Beginners', 'description': 'Learn Python from scratch!'},
    {'id': 2, 'title': 'Web Development with Flask', 'description': 'Build web applications using Flask.'},
    ] @app.route('/') def index():
    return render_template('index.html', courses=courses)
    @app.route('/course/<int:course_id>') def course(course_id):
    course = next((c for c in courses if c&#91;'id'] == course_id), None)
    return render_template('course.html', course=course)
    if __name__ == '__main__':
    app.run(debug=True)

    2. Creating the HTML Templates

    templates/base.html

    <!DOCTYPE html>
    <html lang="en">
    <head>
    
    &lt;meta charset="UTF-8">
    &lt;meta name="viewport" content="width=device-width, initial-scale=1.0">
    &lt;link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
    &lt;title>Online Learning Portal&lt;/title>
    </head> <body>
    &lt;header>
        &lt;h1>Online Learning Portal&lt;/h1>
        &lt;nav>
            &lt;a href="{{ url_for('index') }}">Home&lt;/a>
        &lt;/nav>
    &lt;/header>
    &lt;main>
        {% block content %}{% endblock %}
    &lt;/main>
    &lt;footer>
        &lt;p>&amp;copy; 2024 Online Learning Portal&lt;/p>
    &lt;/footer>
    </body> </html>

    templates/index.html

    {% extends 'base.html' %}
    
    {% block content %}
    <h2>Available Courses</h2>
    <ul>
    
    {% for course in courses %}
        &lt;li>
            &lt;a href="{{ url_for('course', course_id=course.id) }}">{{ course.title }}&lt;/a> - {{ course.description }}
        &lt;/li>
    {% endfor %}
    </ul> {% endblock %}

    templates/course.html

    htmlCopy code{% extends 'base.html' %}
    
    {% block content %}
    <h2>{{ course.title }}</h2>
    <p>{{ course.description }}</p>
    <a href="{{ url_for('index') }}">Back to Courses</a>
    {% endblock %}
    

    3. Adding Some Basic Styles

    static/style.css

    body {
    
    font-family: Arial, sans-serif;
    margin: 0;
    padding: 0;
    } header {
    background: #007BFF;
    color: white;
    padding: 1rem;
    } nav a {
    color: white;
    margin: 0 1rem;
    text-decoration: none;
    } ul {
    list-style: none;
    padding: 0;
    } footer {
    text-align: center;
    padding: 1rem;
    background: #f1f1f1;
    position: relative;
    bottom: 0;
    width: 100%;
    }

    4. Running the App

    1. Navigate to the project directory.
    2. Run the app using the command:bashCopy codepython app.py
    3. Open your web browser and go to http://127.0.0.1:5000/.

    Future Enhancements

    • User authentication (login/signup).
    • Course content management (videos, quizzes).
    • Database integration (like SQLite or PostgreSQL) for persistent data storage.
    • A more complex frontend (using frameworks like React or Vue.js).
  • Social Media Dashboard

    Step 1: Basic Structure (HTML)

    Create an index.html file with the following code:

    <!DOCTYPE html>
    <html lang="en">
    <head>
    
    &lt;meta charset="UTF-8">
    &lt;meta name="viewport" content="width=device-width, initial-scale=1.0">
    &lt;title>Social Media Dashboard&lt;/title>
    &lt;link rel="stylesheet" href="styles.css">
    </head> <body>
    &lt;div class="dashboard">
        &lt;h1>Social Media Dashboard&lt;/h1>
        &lt;div class="cards">
            &lt;div class="card" id="followers-card">
                &lt;h2>Followers&lt;/h2>
                &lt;p id="followers-count">0&lt;/p>
            &lt;/div>
            &lt;div class="card" id="likes-card">
                &lt;h2>Likes&lt;/h2>
                &lt;p id="likes-count">0&lt;/p>
            &lt;/div>
            &lt;div class="card" id="posts-card">
                &lt;h2>Posts&lt;/h2>
                &lt;p id="posts-count">0&lt;/p>
            &lt;/div>
        &lt;/div>
        &lt;button id="update-data">Update Data&lt;/button>
    &lt;/div>
    &lt;script src="script.js">&lt;/script>
    </body> </html>

    Step 2: Basic Styling (CSS)

    Create a styles.css file for the dashboard styling:

    body {
    
    font-family: Arial, sans-serif;
    background-color: #f4f4f4;
    margin: 0;
    padding: 20px;
    } .dashboard {
    max-width: 800px;
    margin: auto;
    padding: 20px;
    background: white;
    border-radius: 10px;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
    } h1 {
    text-align: center;
    } .cards {
    display: flex;
    justify-content: space-between;
    margin-top: 20px;
    } .card {
    flex: 1;
    margin: 0 10px;
    padding: 20px;
    background: #e7e7e7;
    border-radius: 10px;
    text-align: center;
    } button {
    display: block;
    margin: 20px auto;
    padding: 10px 20px;
    background: #007bff;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    } button:hover {
    background: #0056b3;
    }

    Step 3: Adding Functionality (JavaScript)

    Create a script.js file to handle updating the dashboard:

    const followersCount = document.getElementById('followers-count');
    const likesCount = document.getElementById('likes-count');
    const postsCount = document.getElementById('posts-count');
    
    document.getElementById('update-data').addEventListener('click', updateData);
    
    function updateData() {
    
    // Simulated random data for demonstration
    followersCount.textContent = Math.floor(Math.random() * 1000);
    likesCount.textContent = Math.floor(Math.random() * 500);
    postsCount.textContent = Math.floor(Math.random() * 200);
    }

    Explanation

    1. HTML Structure: The HTML creates a basic layout with sections for followers, likes, and posts.
    2. CSS Styling: The CSS styles the dashboard, making it visually appealing with responsive design.
    3. JavaScript Functionality: The JavaScript code simulates updating the data when the button is clicked. In a real application, you’d replace this with API calls to fetch real data.
  • Task Management Tool

    Task Management Tool

    HTML (index.html)

    <!DOCTYPE html>
    <html lang="en">
    <head>
    
    &lt;meta charset="UTF-8">
    &lt;meta name="viewport" content="width=device-width, initial-scale=1.0">
    &lt;title>Task Management Tool&lt;/title>
    &lt;link rel="stylesheet" href="styles.css">
    </head> <body>
    &lt;div class="container">
        &lt;h1>Task Manager&lt;/h1>
        &lt;input type="text" id="taskInput" placeholder="Add a new task...">
        &lt;button id="addTaskButton">Add Task&lt;/button>
        &lt;ul id="taskList">&lt;/ul>
    &lt;/div>
    &lt;script src="script.js">&lt;/script>
    </body> </html>

    CSS (styles.css)

    body {
    
    font-family: Arial, sans-serif;
    background-color: #f4f4f4;
    margin: 0;
    padding: 20px;
    } .container {
    max-width: 600px;
    margin: auto;
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
    } h1 {
    text-align: center;
    } input[type="text"] {
    width: 70%;
    padding: 10px;
    margin-right: 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
    } button {
    padding: 10px;
    background-color: #28a745;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    } button:hover {
    background-color: #218838;
    } ul {
    list-style: none;
    padding: 0;
    } li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px;
    border-bottom: 1px solid #ddd;
    } li.completed {
    text-decoration: line-through;
    color: #aaa;
    } .delete-button {
    background: none;
    border: none;
    color: #dc3545;
    cursor: pointer;
    }

    JavaScript (script.js)

    document.getElementById('addTaskButton').addEventListener('click', addTask);
    document.getElementById('taskInput').addEventListener('keypress', function(e) {
    
    if (e.key === 'Enter') {
        addTask();
    }
    }); function addTask() {
    const taskInput = document.getElementById('taskInput');
    const taskText = taskInput.value.trim();
    
    if (taskText === '') {
        alert('Please enter a task');
        return;
    }
    const li = document.createElement('li');
    li.textContent = taskText;
    const completeButton = document.createElement('button');
    completeButton.textContent = '✓';
    completeButton.onclick = () => {
        li.classList.toggle('completed');
    };
    
    const deleteButton = document.createElement('button');
    deleteButton.textContent = '✖';
    deleteButton.classList.add('delete-button');
    deleteButton.onclick = () => {
        li.remove();
    };
    li.appendChild(completeButton);
    li.appendChild(deleteButton);
    document.getElementById('taskList').appendChild(li);
    
    taskInput.value = '';
    }

    How to Run

    1. Create a Project Directory: Create a folder for your project, e.g., task-manager.
    2. Create Files: Inside this folder, create three files: index.html, styles.css, and script.js.
    3. Copy the Code: Copy the HTML, CSS, and JavaScript code provided above into their respective files.
    4. Open in a Browser: Open index.html in your web browser to see the task management tool in action.

  • E-commerce Platform

    Step 1: Set Up Your Environment

    Make sure you have Python installed, and then set up a virtual environment:

    mkdir ecommerce-platform
    cd ecommerce-platform
    python -m venv venv
    source venv/bin/activate  # On Windows use venv\Scripts\activate
    pip install Flask SQLAlchemy
    

    Step 2: Create the Project Structure

    Your project structure should look like this:

    arduinoCopy codeecommerce-platform/
    │
    ├── app.py
    ├── models.py
    ├── templates/
    │   ├── index.html
    │   ├── product.html
    │   └── cart.html
    └── static/
    
    └── style.css

    Step 3: Define the Models (models.py)

    Create a file named models.py for your database models.

    from flask_sqlalchemy import SQLAlchemy
    
    db = SQLAlchemy()
    
    class Product(db.Model):
    
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(100), nullable=False)
    price = db.Column(db.Float, nullable=False)
    description = db.Column(db.String(200), nullable=True)

    Step 4: Set Up the Application (app.py)

    Create a file named app.py for your application logic.

    from flask import Flask, render_template
    from models import db, Product
    
    app = Flask(__name__)
    app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///ecommerce.db'
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
    db.init_app(app)
    
    with app.app_context():
    
    db.create_all()
    @app.route('/') def index():
    products = Product.query.all()
    return render_template('index.html', products=products)
    @app.route('/product/<int:product_id>') def product(product_id):
    product = Product.query.get(product_id)
    return render_template('product.html', product=product)
    if __name__ == '__main__':
    app.run(debug=True)

    Step 5: Create the Frontend (HTML Templates)

    1. index.html
    <!DOCTYPE html>
    <html lang="en">
    <head>
    
    &lt;meta charset="UTF-8">
    &lt;meta name="viewport" content="width=device-width, initial-scale=1.0">
    &lt;link rel="stylesheet" href="/static/style.css">
    &lt;title>My E-Commerce Store&lt;/title>
    </head> <body>
    &lt;h1>Products&lt;/h1>
    &lt;ul>
        {% for product in products %}
        &lt;li>
            &lt;a href="{{ url_for('product', product_id=product.id) }}">{{ product.name }}&lt;/a>
            - ${{ product.price }}
        &lt;/li>
        {% endfor %}
    &lt;/ul>
    </body> </html>
    1. product.html
    <!DOCTYPE html>
    <html lang="en">
    <head>
    
    &lt;meta charset="UTF-8">
    &lt;meta name="viewport" content="width=device-width, initial-scale=1.0">
    &lt;link rel="stylesheet" href="/static/style.css">
    &lt;title>{{ product.name }}&lt;/title>
    </head> <body>
    &lt;h1>{{ product.name }}&lt;/h1>
    &lt;p>{{ product.description }}&lt;/p>
    &lt;p>Price: ${{ product.price }}&lt;/p>
    &lt;a href="/">Back to products&lt;/a>
    </body> </html>
    1. cart.html (Optional for future expansion)

    You can expand this later with cart functionality.

    Step 6: Add Some Styles (style.css)

    Create a file named style.css in the static folder for basic styling.

    cssCopy codebody {
    
    font-family: Arial, sans-serif;
    margin: 20px;
    } h1 {
    color: #333;
    } ul {
    list-style-type: none;
    padding: 0;
    } li {
    margin: 10px 0;
    }

    Step 7: Running the Application

    To run your application, use the following command:

    bashCopy codepython app.py
    

    Visit http://127.0.0.1:5000 in your browser to see your e-commerce platform!