Maaaaaaaaa
Maaaaaaaaa
DM1: To provide strong fundamentals and technical skills for Computer Science
applications through effective teaching learning methodologies.
Graduate
S. No Program Outcomes
Attribute
Engineering knowledge Apply the knowledge of Mathematics, Science, engineering fundamentals,
PO1 and an engineering specialization to the solution of
complex engineering problems.
Identify, formulate, review research literature, and analyze complex engineering
PO2 Problem analysis problems reaching substantiated conclusions using first principles of
Mathematics, natural sciences, and
engineering sciences.
Design solutions for complex engineering problems and design system
Design/development of components or processes that meet the specified needs with appropriate
PO3
solutions consideration for the public health and safety, and the
cultural, societal, and environmental considerations.
Conduct Use research-based knowledge and research methods including design of
PO4 investigations of experiments, analysis and interpretation of data, and synthesis of the information
complex problems to provide valid conclusions.
Project management Demonstrate knowledge and understanding of the engineering and management
PO11 and finance principles and apply these to one’s own work, as a member and leader in a
team, to manage projects and in
multidisciplinary environments.
PO12 Life-long learning Recognize the need for, and have the preparation and ability to engage in
independent and life-long learning in the broadest
context of technological change.
COURSEOUTCOMES
PO 1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12 PSO1 PSO2
CO1
2 2 2 1 1 1 2
CO2 1
2 2 2 1 1 2
CO3
2 2 2 1 1 1 2
CO4
2 2 2 1 1 1 2
CO5
2 2 2 1 1 1 2
Average 2 2 2 1 1 1 2
INDEX
Page CO’s
S.No. Date Title of the Project PO’s, PS0’s Mapped Signature
No. Mapped
PO1,PO2,PO3,
PO4,PO11,PO12,
Simple Weather Application PSO1
1 1 CO1,CO2
PO1,PO2,PO3,
PO4,PO11,PO12,
URL shortener Application CO1,CO2,
PSO1
2 using SQL. 6 CO3,CO4
PO1,PO2,PO3,
Flight ticket booking PO4,PO11,PO12,
CO1,CO2,
Application using any tech PSO1
3 15 CO3,CO4
stack
Expt.No:1
SIMPLE WEATHER APPLICATION
Date:
Aim:
1. Node.js Installation: Ensure that Node.js is installed and available on the system.
Node.js is used to run server-side JavaScript code.
4. Install Dependencies: Use npm (Node Package Manager) to install the required
dependencies for the project. The following packages are used:
axios: A popular HTTP client for making API requests.
dotenv: A package for loading environment variables from a .env file.
readline: A package for reading input from the command line.
5. Application Program (weather.js): This JavaScript file contains the server-side code
for the weather application. It includes the following features:
Fetching weather data from the OpenWeatherMap API using the provided API
key.
Creating an HTTP server to serve an HTML page and handle weather
information requests.
Parsing query parameters from the URL to retrieve the user's desired location.
Displaying weather information on the HTML page and handling errors.
6. HTML Template (index.html): This HTML file is the user interface for the weather
application. It includes a form where users can input a city name (and optionally, a
country code). The weather information is displayed below the form. The HTML file
also includes JavaScript code to make AJAX requests to the server and update the
page with weather data.
Output:
When users input a valid location, the application fetches and displays the city name,
temperature, and weather description.
1
Execution Steps:
Node.js should be installed and available.
Ensure you have Node.js installed by running the following commands in the terminal:
node -v
npm -v
If you don't have Node.js, download and install it from https://nodcjs.org.
Get OpenWeatherMap API Key
Sign up on OpenWeatherMap
https://home.openweathermap.org/users/sign_up
1. After creating your account, navigate to the API section to generate a new API key or use the
default one provided. [NOTE: Ensure your email adt11'ess is verifietl, and allow a few hours
for the l‹ey to becom e active.]
2. Note this API key, which will be needed for the app.
Generate API key
Create a Project Directory.
Create a directory for your weather app:
mkdir weather-app
cd weather-app
Now install the required dependencies:
In the project directory, initialize a Node.js project:
npm init -y
This will create a package.json file. Now install the required dependencies:
npm install axios dotenv readline
Create .env File for API key
Create a file named ’.env" in your project directory:
In the ”.env’ file, add your OpenWeatherMap API key like this:
API_KEY
Replace ’your_openweathermap_api_key’ with your actual API key.
Step 6: Create weather.js
This file will contain the Node.js logic for fetching the weather data and serving the HTML page.
2
Application Program
weather.js
// Make an AJAX request to the server with the location as a query parameter
const response = await
fetch(`/weather?location=${encodeURIComponent(location)}`);
const weatherData = await response.json();
node weather.js
Output
C:\node-one>node weather.js
Server is running on http://localhost:3000
5
Conclusion:
This application allows to input a city name (and optionally, a country code), and it
fetches and displays the weather information for that location. Overall, this project
demonstrates the creation of a basic web application using Node.js and serves as an example
of how to interact with an external API (OpenWeatherMap) to fetch and display real-time
weather data. Users can access the weather information through a user-friendly web interface.
6
Expt.No:2
URL SHORTENER APPLICATION USING SQL
Date:
Aim:
1. Python and Django: Ensure you have Python installed on your system. Also need
Django, which can be installed using pip.
2. Database: Decide on the SQL database want to use (e.g., SQLite, PostgreSQL,
MySQL) and ensure it is installed and running.
3. Django App: Create a Django project and an app within the project where your URL
shortener functionality will reside.
4. Models: Define a Django model to represent URLs. This model should include fields
for the original (long) URL, the shortened URL, and any other relevant information
you want to store.
5. Views: Create views for your URL shortener application. This views is needed for the
home page, URL submission form, and redirection. These views should interact with
your model to retrieve and store URLs.
6. Templates: Design HTML templates for your application's pages, including the home
page, URL submission form, and redirection page.
7. URL Routing: Configure URL patterns in your app's urls.py file to route requests to
the appropriate views.
8. Forms: Create a Django form for the URL submission form. This form should
validate and process user input.
10. Database Configuration: Configure the Django project settings to use the SQL
database of your choice (e.g., SQLite or PostgreSQL). Update the DATABASES
setting in settings.py.
11. Migrations: Run migrations to create the database tables based on your models.
12. Static and Media Files: Configure static and media file handling in your Django
project settings if you plan to use CSS, JavaScript, or store user-uploaded files.
13. User Interface: Design and style the application's user interface using CSS or a
frontend framework if desired.
7
14. Deployment: Choose a hosting platform (e.g., Heroku, AWS, DigitalOcean) for
deploying the Django application in a production environment.
15. Domain and DNS: If needed to use a custom domain for the URL shortener, set up
DNS records to point to the application's server.
Execution Steps:
1. Create Virtual Environment (Recommended):
python -m venv myenv
myenv\Scripts\activate
2. Install Django, SQLAlchemy other necessary packages:
pip install Django
pip install SQLAlchemy
3. Create a Django Project and an Application:
python -m django startproject urlshortener
If any issues Re-Install Django as follows
pip uninstall django
pip install Django
cd urlshortener
python manage.py startapp urlshort
4. Create Database and apply Migrations:
Run the following commands to create default database and apply migrations:
python manage.py makemigrations
python manage.py migrate
5. Configure Database:
In the project's settings (urlshortener/settings.py), configure the database to use SQLite:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'urlshort',
]
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
6. Define Models:
In the urlshort/models.py file, define the data models using Django's ORM (Object-
Relational Mapping).
# urlshort/models.py
8
from django.contrib.auth.models import User
from django.db import models
class URL(models.Model):
long_url = models.URLField(unique=True)
short_url = models.CharField(max_length=20, unique=True)
class UrlModel(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE)
original_url = models.URLField()
short_url = models.CharField(max_length=20, unique=True)
7. Define Views:
In the urlshort/views.py file, create views in your app's views.py to handle requests and
responses.
# urlshort/views.py
from django.shortcuts import render, redirect, get_object_or_404
from .models import URL
from .utils import generate_short_url
def home(request):
# Fetch a list of all stored URLs
urls = URL.objects.all()
return render(request, 'urlshort/home.html', {'urls': urls})
def shorten_url(request):
if request.method == 'POST':
long_url = request.POST['long_url']
short_url = generate_short_url()
url = URL(long_url=long_url, short_url=short_url)
url.save()
return redirect('home')
return render(request, 'urlshort/shorten_url.html')
8. Define utils:
In the urlshort/utils.py file, simple function to generate short URLs using random characters
is created.
import random
import string
def generate_short_url():
"""
Generate a random short URL using alphanumeric characters.
You can customize the length and characters used as needed.
"""
# Define the characters to choose from for the short URL
characters = string.ascii_letters + string.digits # Alphanumeric characters
# Set the desired length of the short URL
short_url_length = 6 # You can adjust this to your preference
# Generate a random short URL
9
short_url = ''.join(random.choice(characters) for _ in range(short_url_length))
return short_url
9. Create Templates:
home.html
<!-- urlshort/templates/urlshort/home.html -->
<!DOCTYPE html>
<html>
<head>
<title>URL Shortener</title>
</head>
<body>
<h1>Welcome to the URL Shortener</h1>
<h2>Stored URLs:</h2>
<ul>
{% for url in urls %}
<li><a href="{{ url.short_url }}">{{ url.short_url }}</a></li>
{% empty %}
<p>No URLs stored yet.</p>
{% endfor %}
</ul>
<form method="post">
{% csrf_token %}
<label for="long_url">Enter a long URL:</label>
<input type="url" id="long_url" name="long_url" required>
<input type="submit" value="Shorten">
10
</form>
</body>
</html>
redirect.html
<!-- urlshort/templates/urlshort/redirect.html -->
<!DOCTYPE html>
<html>
<head>
<title>URL Shortener - Redirecting...</title>
</head>
<body>
<h1>Redirecting...</h1>
<p>You will be redirected to the original URL in a moment.</p>
</body>
</html>
10. Update Project and App URLs:
# urlshort/urls.py (inside your app)
from django.urls import path
from . import views
urlpatterns = [
path('', views.home, name='home'),
path('shorten/', views.shorten_url, name='shorten_url'),
path('<str:short_url>/', views.redirect_to_original, name='redirect_to_original'),
]
11
Start the Django development server:
14. Outputs:
12
13
After Clicking IafA1A
Conclusion:
The URL Shortener Application using SQL and Django provides shortening of any
URL and linking to the actual Webpage when clicked on the shortened URL content. It fulfils
the basic requirements of URL shortening and redirection. In expansion and improvement, it
can be refined and enhanced with the application based on user feedback and evolving
requirements.
14
Expt.No:3
FLIGHT TICKET BOOKING USING ANY TECH STACK
Date:
Aim:
To create a web application for flight ticket booking using any tech stack for the backend and
database.
Scenarios Considered:
Type of Users
a. User
b. Admin
3. My Bookings
Create a "My Bookings" route where users can view all the bookings they've made. This
route should query the database for bookings associated with the logged-in user and display
the results.
4. Logout
Implement a logout functionality that clears the user's session and redirects them to the login
page.
15
Admin Use Cases:
1. Admin Login
Create a separate login route and authentication system for administrators.
2. Add Flights
Implement a route for administrators to add new flights to the system. This route should
allow the admin to input flight details, including flight number, date, time, and available
seats.
3. Remove Flights
Create a route for administrators to remove flights from the system. This route should allow
the admin to select a flight by its flight number and remove it from the database.
Tech Stack:
Create a directory for your project and set up a virtual environment for Python.
mkdir flight_booking_app
cd flight_booking_app
python -m venv venv
venv\Scripts\activate
class LoginForm(FlaskForm):
username = StringField('Username', validators=[DataRequired()])
password = PasswordField('Password', validators=[DataRequired()])
submit = SubmitField('Login')
class FlightForm(FlaskForm):
flight_number = StringField('Flight Number', validators=[DataRequired()])
departure_city = StringField('Departure City', validators=[DataRequired()])
arrival_city = StringField('Arrival City', validators=[DataRequired()])
departure_time = DateTimeField('Departure Time', validators=[DataRequired()],
format='%Y-%m-%d %H:%M:%S')
submit = SubmitField('Add Flight')
class Flight(db.Model):
id = db.Column(db.Integer, primary_key=True)
flight_number = db.Column(db.String(10), unique=True, nullable=False)
departure_city = db.Column(db.String(50), nullable=False)
arrival_city = db.Column(db.String(50), nullable=False)
departure_time = db.Column(db.DateTime, default=datetime.utcnow)
bookings = db.relationship('Booking', backref='flight', lazy=True)
class Booking(db.Model):
id = db.Column(db.Integer, primary_key=True)
user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
flight_id = db.Column(db.Integer, db.ForeignKey('flight.id'), nullable=False)
booking_date = db.Column(db.DateTime, default=datetime.utcnow)
@app.route('/dashboard')
@login_required
def dashboard():
# Fetch the user's bookings
bookings = Booking.query.filter_by(user_id=current_user.id).all()
return render_template('dashboard.html', bookings=bookings)
@app.route('/logout')
@login_required
def logout():
logout_user()
return redirect(url_for('login'))
@app.route('/remove_flight/<int:flight_id>', methods=['POST'])
@login_required
def remove_flight(flight_id):
19
flight = Flight.query.get(flight_id)
if flight:
db.session.delete(flight)
db.session.commit()
flash('Flight removed successfully!', 'success')
else:
flash('Flight not found.', 'danger')
return redirect(url_for('dashboard'))
@app.route('/')
def home():
return "Welcome to the Flight Booking App!"
if name == ' main ':
with app.app_context():
db.create_all()
app.run(debug=True)
Step 4: Define the required models
# models.py
from flask_sqlalchemy import SQLAlchemy
from datetime import datetime
from app import db
class Flight(db.Model):
id = db.Column(db.Integer, primary_key=True)
flight_number = db.Column(db.String(10), unique=True, nullable=False)
departure_city = db.Column(db.String(50), nullable=False)
arrival_city = db.Column(db.String(50), nullable=False)
departure_time = db.Column(db.DateTime, default=datetime.utcnow)
# Add more fields as needed
class Booking(db.Model):
id = db.Column(db.Integer, primary_key=True)
user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
flight_id = db.Column(db.Integer, db.ForeignKey('flight.id'), nullable=False)
booking_date = db.Column(db.DateTime, default=datetime.utcnow)
# Add more fields as needed
20
Step 5: Design the templates required
registration.html
<!DOCTYPE html>
<html>
<head>
<title>Registration</title>
</head>
<body>
<h1>Registration</h1>
<form method="POST" action="{{ url_for('register') }}">
{{ form.hidden_tag() }}
<label for="username">Username:</label>
{{ form.username(class="form-control") }}
<label for="password">Password:</label>
{{ form.password(class="form-control") }}
{{ form.submit(class="btn btn-primary") }}
</form>
<p>Already have an account? <a href="{{ url_for('login') }}">Login</a></p>
</body>
</html>
login.html
<!DOCTYPE html>
<html>
<head>
<title>Login</title>
</head>
<body>
<h1>Login</h1>
<form method="POST" action="{{ url_for('login') }}">
{{ form.hidden_tag() }}
<label for="username">Username:</label>
{{ form.username(class="form-control") }}
<label for="password">Password:</label>
{{ form.password(class="form-control") }}
{{ form.submit(class="btn btn-primary") }}
</form>
<p>Don't have an account? <a href="{{ url_for('register') }}">Register</a></p>
</body>
</html>
dashboard.html
<!DOCTYPE html>
<html>
<head>
<title>Dashboard</title>
</head>
<body>
<h1>Welcome to Your Dashboard, {{ current_user.username }}!</h1>
21
<p>Your Bookings:</p>
<ul>
{% for booking in bookings %}
<li>{{ booking.flight.departure_city }} to {{ booking.flight.arrival_city }}</li>
{% endfor %}
</ul>
<p><a href="{{ url_for('logout') }}">Logout</a></p>
</body>
</html>
book_flight.html
<!DOCTYPE html>
<html>
<head>
<title>Book a Flight</title>
</head>
<body>
<h1>Book a Flight</h1>
<form method="POST" action="{{ url_for('book_flight', flight_id=flight.id) }}">
{{ form.hidden_tag() }}
<label>Flight Information:</label>
<p>Flight Number: {{ flight.flight_number }}</p>
<p>Departure City: {{ flight.departure_city }}</p>
<p>Arrival City: {{ flight.arrival_city }}</p>
<label for="booking_date">Booking Date:</label>
{{ form.booking_date(class="form-control") }}
{{ form.submit(class="btn btn-primary") }}
</form>
</body>
</html>
add_flight.html
<!DOCTYPE html>
<html>
<head>
<title>Add a Flight</title>
</head>
<body>
<h1>Add a Flight</h1>
<form method="POST" action="{{ url_for('add_flight') }}">
{{ form.hidden_tag() }}
<label for="flight_number">Flight Number:</label>
{{ form.flight_number(class="form-control") }}
<label for="departure_city">Departure City:</label>
{{ form.departure_city(class="form-control") }}
<label for="arrival_city">Arrival City:</label>
{{ form.arrival_city(class="form-control") }}
<label for="departure_time">Departure Time:</label>
{{ form.departure_time(class="form-control") }}
22
{{ form.submit(class="btn btn-primary") }}
</form>
</body>
</html>
booked_flight.html
<!DOCTYPE html>
<html>
<head>
<title>Your Booked Flights</title>
</head>
<body>
<h1>Your Booked Flights</h1>
<ul>
{% for booking in bookings %}
<li>{{ booking.flight.departure_city }} to {{ booking.flight.arrival_city }}</li>
{% endfor %}
</ul>
<p><a href="{{ url_for('dashboard') }}">Back to Dashboard</a></p>
</body>
</html>
view_bookings.html
<!DOCTYPE html>
<html>
<head>
<title>View Bookings for Flight</title>
</head>
<body>
<h1>View Bookings for Flight {{ flight.flight_number }}</h1>
<p>Departure City: {{ flight.departure_city }}</p>
<p>Arrival City: {{ flight.arrival_city }}</p>
<p>Departure Time: {{ flight.departure_time }}</p>
<h2>Bookings:</h2>
<ul>
{% for booking in bookings %}
<li>{{ booking.user.username }} (Booking Date: {{ booking.booking_date }})</li>
{% endfor %}
</ul>
<p><a href="{{ url_for('dashboard') }}">Back to Dashboard</a></p>
</body>
</html>
Step 6: Create Database Tables:
Within the Python shell type as
from app import db
db.create_all()
exit()
23
CREATE TABLE flights (
flight_id INT AUTO_INCREMENT PRIMARY KEY,
flight_number VARCHAR(10) NOT NULL,
source VARCHAR(50) NOT NULL,
destination VARCHAR(50) NOT NULL,
date DATE NOT NULL,
time TIME NOT NULL,
seats_available INT NOT NULL
);
Step 7: Create init .py to import SQLALchemy and its dependencies
init .py
# app/ init .py
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
def create_app():
app = Flask( name )
app.config['SECRET_KEY'] = 'your-secret-key'
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///flight_booking.db'
db.init_app(app)
return app
app = create_app()
Step 8: Structure the flask application as follows
project_folder/
venv/ (virtual environment)
app/
init .py
models.py
routes.py
templates/
registration.html
login.html
dashboard.html
book_flight.html
add_flight.html
booked_flights.html
view_bookings.html
app.py
requirements.txt
Step 9: Run the application
(new_venv3) C:\node-example\flight_booking_app>python app.py
C:\node-example\flight_booking_app\new_venv3\Lib\site-
packages\flask_sqlalchemy\ init .py:872: FSADeprecationWarning:
SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be
disabled by default in the future. Set it to True or False to suppress this warning.
warnings.warn(FSADeprecationWarning(
* Serving Flask app 'app' (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
24
Use a production WSGI server instead.
* Debug mode: on
* Restarting with stat
C:\node-example\flight_booking_app\new_venv3\Lib\site-
packages\flask_sqlalchemy\ init .py:872: FSADeprecationWarning:
SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be
disabled by default in the future. Set it to True or False to suppress this warning.
warnings.warn(FSADeprecationWarning(
* Debugger is active!
* Debugger PIN: 795-665-397
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
Output:
25
Conclusion:
This project is created using a Flask application with a simple flight booking form.
When a user submits the form, the booking details are saved to a SQLite database. This
implementation can be adapted and extended to meet any additional specific requirements,
including payment integration, ticket generation, and confirmation emails. Additionally, it
would be needed to create HTML templates for the form and booking confirmation pages.
This is a simplified example, and a production-grade flight booking system would
require more extensive features, including user authentication, flight availability checks, and
robust payment processing.
This project includes a simple flight booking system with user registration and booking
credentials.
26