diff --git a/Sanjana-Easy/Task 1/Task1.py b/Sanjana-Easy/Task 1/Task1.py new file mode 100644 index 0000000..c47dcb2 --- /dev/null +++ b/Sanjana-Easy/Task 1/Task1.py @@ -0,0 +1,71 @@ +import requests +from bs4 import BeautifulSoup +import csv +import json + +# URL to fetch +url = "https://www.techadvisor.com/article/724318/best-smartphone.html" + +# Perform the HTTP GET request +response = requests.get(url) + +# Parse the HTML content with BeautifulSoup +soup = BeautifulSoup(response.content, 'html.parser') + +# Extract the phone names +phones = soup.find_all(class_='product-chart-item__title-wrapper--title') +phone_names = [h2.get_text(strip=True) for h2 in phones] + +# Initialize lists for pros and cons +all_pros = [] +all_cons = [] + +# Extract the pros and cons lists +pros_divs = soup.find_all('div', class_='product-chart-column') +for div in pros_divs: + title = div.find('p', class_='product-chart-subTitle').get_text(strip=True) + ul = div.find('ul', class_='product-pros-cons-list') + if title == 'Pros': + pros = [li.get_text(strip=True) for li in ul.find_all('li')] + all_pros.append(pros) + elif title == 'Cons': + cons = [li.get_text(strip=True) for li in ul.find_all('li')] + all_cons.append(cons) + +# Combine the phone names, pros, and cons into a structured format +phones_data = [] +for i in range(len(phone_names)): + phone_data = { + "phone": phone_names[i], + "pros": all_pros[i] if i < len(all_pros) else [], + "cons": all_cons[i] if i < len(all_cons) else [] + } + phones_data.append(phone_data) + +# Print the combined data +for phone in phones_data: + print(f"Phone: {phone['phone']}") + print("Pros:") + for pro in phone['pros']: + print(f" - {pro}") + print("Cons:") + for con in phone['cons']: + print(f" - {con}") + print('-------------------') + +# Save the structured data to JSON +with open('phones_data.json', 'w', encoding='utf-8') as jsonfile: + json.dump(phones_data, jsonfile, indent=4) + +print("Extracted data saved to phones_data.json") + +# Save the structured data to CSV +with open('phones_data.csv', 'w', newline='', encoding='utf-8') as csvfile: + writer = csv.writer(csvfile) + writer.writerow(["Phone", "Pros", "Cons"]) + for phone in phones_data: + pros = "; ".join(phone["pros"]) + cons = "; ".join(phone["cons"]) + writer.writerow([phone["phone"], pros, cons]) + +print("Extracted data saved to phones_data.csv") diff --git a/Sanjana-Easy/Task 1/requirements.txt b/Sanjana-Easy/Task 1/requirements.txt new file mode 100644 index 0000000..936ba4d --- /dev/null +++ b/Sanjana-Easy/Task 1/requirements.txt @@ -0,0 +1,2 @@ +beautifulsoup4==4.12.3 +Requests==2.32.3 diff --git a/Sanjana-Easy/Task 2/Task2.py b/Sanjana-Easy/Task 2/Task2.py new file mode 100644 index 0000000..ac51e19 --- /dev/null +++ b/Sanjana-Easy/Task 2/Task2.py @@ -0,0 +1,44 @@ +import nltk +from nltk.chat.util import Chat, reflections +nltk.download('punkt') +#creating questions and answers +s=[ + [ + r"Hello|Hi|Hey", + ["Hello,How are you?"] + ], + [ + r"I'm fine", + ["Glad to hear that,how can i help you?"] + ], + [ + r"What is your name?", + ["well they haven't kept me a name but they call me as a chatbot ,if you wish u can give me a name"] + ], + [ + r"Actually I'm feeling a bit lonely|sad|angry|irritated today", + ["sorry to hear about that.I'm here for you! Would you like to share about what's on your mind?"] + ], + [ + r"Yeah well that was a big problem, i can't get rid off it", + ["I'm really sorry to hear about that you are going through a tough time.It's okay to feel overwhelmed by problems sometimes but dont worry that you are not at all alone!"] + ], + [ + r"Can you try to say something lie a joke or entertain me?", + ["Sure,I can definitely change your mood!So,how about this:Why maths book look sad?Because it had any problems!I hope that this brought a little smile to your face!"] + ], + [ + r"Thanks a lot for helping me", + ["You're Welcome!I'm always here for you at anytime,if you need a chat or joke or anything,feel free to ask me"] + ], + [ + r"Exit", + ["It was my pleasure to help you.Please,come again!"] + ] +] +#default message for starting chat +print("Please,write anything to start the chat") +#create a chat instance +chatbot=Chat(s) +#start conversation +chatbot.converse() \ No newline at end of file diff --git a/Sanjana-Easy/Task 2/requirements.txt b/Sanjana-Easy/Task 2/requirements.txt new file mode 100644 index 0000000..c36259a --- /dev/null +++ b/Sanjana-Easy/Task 2/requirements.txt @@ -0,0 +1 @@ +nltk==3.8.1 diff --git a/Sanjana-Easy/Task 3/Procfile b/Sanjana-Easy/Task 3/Procfile new file mode 100644 index 0000000..0f1a73d --- /dev/null +++ b/Sanjana-Easy/Task 3/Procfile @@ -0,0 +1 @@ +web:gunicorn app:app \ No newline at end of file diff --git a/Sanjana-Easy/Task 3/Task3.py b/Sanjana-Easy/Task 3/Task3.py new file mode 100644 index 0000000..321e287 --- /dev/null +++ b/Sanjana-Easy/Task 3/Task3.py @@ -0,0 +1,189 @@ + +# app.py +from flask import Flask, render_template +from flask_sqlalchemy import SQLAlchemy +from flask_login import LoginManager , UserMixin +from flask_migrate import Migrate +from datetime import datetime + + + + + + +app = Flask(__name__) +app.app_context().push() +app.config['SECRET_KEY'] = 'your_secret_key_here' # Change this to a random secret key +app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///tasks.db' # Database file will be created in the project folder +app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False +db = SQLAlchemy(app) +login_manager = LoginManager(app) +login_manager.login_view = 'login' + + +migrate = Migrate(app, db) + + +class Task(db.Model): + id = db.Column(db.Integer, primary_key=True) + title = db.Column(db.String(100), nullable=False) + description = db.Column(db.Text, nullable=True) + due_date = db.Column(db.DateTime, default=datetime.utcnow) + completed = db.Column(db.Boolean, default=False) + user_id = db.Column(db.Integer, db.ForeignKey('user.id', name='fk_task_user'), nullable=False) + +class User(UserMixin , db.Model): + id = db.Column(db.Integer, primary_key=True) + username = db.Column(db.String(50), unique=True, nullable=False) + password = db.Column(db.String(100), nullable=False) + + +from flask import redirect, url_for, request, flash +from flask_login import login_user, login_required, logout_user, current_user + +from flask import render_template, redirect, url_for, request, flash +from flask_login import login_user, login_required, logout_user, current_user +from werkzeug.security import generate_password_hash, check_password_hash + + + +# Implement the Logic + +@app.route('/', methods=['GET', 'POST']) +def register(): + if request.method == 'POST': + username = request.form['username'] + password = request.form['password'] + + existing_user = User.query.filter_by(username=username).first() + if existing_user: + flash('Username already exists. Please choose a different username.', 'danger') + return redirect(url_for('register')) + + new_user = User(username=username, password=generate_password_hash(password, method='pbkdf2:sha256')) + db.session.add(new_user) + db.session.commit() + + flash('Registration successful. You can now log in.', 'success') + return redirect(url_for('login')) + + return render_template('register.html') + + +@app.route('/login', methods=['GET', 'POST']) +def login(): + if request.method == 'POST': + username = request.form['username'] + password = request.form['password'] + + user = User.query.filter_by(username=username).first() + + if user and check_password_hash(user.password, password): + login_user(user) + flash('Logged in successfully!', 'success') + return redirect(url_for('dashboard')) + else: + flash('Invalid username or password. Please try again.', 'danger') + + return render_template('login.html') + + +@app.route('/dashboard') +@login_required +def dashboard(): + tasks = Task.query.filter_by(user_id=current_user.id).all() + return render_template('dashboard.html', tasks=tasks) + + +@app.route('/add_task', methods=['GET', 'POST']) +@login_required +def add_task(): + if request.method == 'POST': + title = request.form['title'] + description = request.form['description'] + due_date_str = request.form['due_date'] + + due_date = datetime.strptime(due_date_str, '%Y-%m-%d') + + new_task = Task(title=title, description=description, due_date=due_date, user_id=current_user.id) + db.session.add(new_task) + db.session.commit() + + flash('Task added successfully!', 'success') + return redirect(url_for('dashboard')) + + return render_template('add_task.html') + + +@app.route('/edit_task/', methods=['GET', 'POST']) +@login_required +def edit_task(task_id): + task = Task.query.get_or_404(task_id) + + if task.user_id != current_user.id: + flash('You are not authorized to edit this task.', 'danger') + return redirect(url_for('dashboard')) + + if request.method == 'POST': + task.title = request.form['title'] + task.description = request.form['description'] + task.due_date_str = request.form['due_date'] + task.due_date = datetime.strptime(task.due_date_str, '%Y-%m-%d') + + + + + db.session.commit() + + flash('Task updated successfully!', 'success') + return redirect(url_for('dashboard')) + + return render_template('edit_task.html', task=task) + + +@app.route('/delete_task/', methods=['POST']) +@login_required +def delete_task(task_id): + task = Task.query.get_or_404(task_id) + + if task.user_id != current_user.id: + flash('You are not authorized to delete this task.', 'danger') + return redirect(url_for('dashboard')) + + db.session.delete(task) + db.session.commit() + + flash('Task deleted successfully!', 'success') + return redirect(url_for('dashboard')) + + + +from flask_login import LoginManager, UserMixin, login_user, login_required, logout_user, current_user + +#Implement Authentication and Authorization + +# Create a user loader function required by flask_login +@login_manager.user_loader +def load_user(user_id): + return User.query.get(int(user_id)) + + + + + +@login_manager.unauthorized_handler +def unauthorized(): + flash('You must be logged in to access that page.', 'danger') + return redirect(url_for('login')) + +@app.route('/logout') +@login_required +def logout(): + logout_user() + flash('Logged out successfully.', 'success') + return redirect(url_for('login')) + + +if __name__ == '__main__': + db.create_all() + app.run(debug=True) \ No newline at end of file diff --git a/Sanjana-Easy/Task 3/__pycache__/app.cpython-311.pyc b/Sanjana-Easy/Task 3/__pycache__/app.cpython-311.pyc new file mode 100644 index 0000000..30ebfce Binary files /dev/null and b/Sanjana-Easy/Task 3/__pycache__/app.cpython-311.pyc differ diff --git a/Sanjana-Easy/Task 3/instance/tasks.db b/Sanjana-Easy/Task 3/instance/tasks.db new file mode 100644 index 0000000..bea79a0 Binary files /dev/null and b/Sanjana-Easy/Task 3/instance/tasks.db differ diff --git a/Sanjana-Easy/Task 3/migrations/README b/Sanjana-Easy/Task 3/migrations/README new file mode 100644 index 0000000..bc8f3dd --- /dev/null +++ b/Sanjana-Easy/Task 3/migrations/README @@ -0,0 +1 @@ +Single-database configuration for Flask. diff --git a/Sanjana-Easy/Task 3/migrations/__pycache__/env.cpython-311.pyc b/Sanjana-Easy/Task 3/migrations/__pycache__/env.cpython-311.pyc new file mode 100644 index 0000000..1d436f2 Binary files /dev/null and b/Sanjana-Easy/Task 3/migrations/__pycache__/env.cpython-311.pyc differ diff --git a/Sanjana-Easy/Task 3/migrations/alembic.ini b/Sanjana-Easy/Task 3/migrations/alembic.ini new file mode 100644 index 0000000..e7c72d1 --- /dev/null +++ b/Sanjana-Easy/Task 3/migrations/alembic.ini @@ -0,0 +1,50 @@ +# A generic, single database configuration. + +[alembic] +# template used to generate migration files +# file_template = %%(rev)s_%%(slug)s + +# set to 'true' to run the environment during +# the 'revision' command, regardless of autogenerate +# revision_environment = false + + +# Logging configuration +[loggers] +keys = root,sqlalchemy,alembic,flask_migrate + +[handlers] +keys = console + +[formatters] +keys = generic + +[logger_root] +level = WARN +handlers = console +qualname = + +[logger_sqlalchemy] +level = WARN +handlers = +qualname = sqlalchemy.engine + +[logger_alembic] +level = INFO +handlers = +qualname = alembic + +[logger_flask_migrate] +level = INFO +handlers = +qualname = flask_migrate + +[handler_console] +class = StreamHandler +args = (sys.stderr,) +level = NOTSET +formatter = generic + +[formatter_generic] +format = %(levelname)-5.5s [%(name)s] %(message)s +datefmt = %H:%M:%S diff --git a/Sanjana-Easy/Task 3/migrations/env.py b/Sanjana-Easy/Task 3/migrations/env.py new file mode 100644 index 0000000..2e4a5fa --- /dev/null +++ b/Sanjana-Easy/Task 3/migrations/env.py @@ -0,0 +1,113 @@ +import logging +from logging.config import fileConfig + +from flask import current_app + +from alembic import context + +# this is the Alembic Config object, which provides +# access to the values within the .ini file in use. +config = context.config + +# Interpret the config file for Python logging. +# This line sets up loggers basically. +fileConfig(config.config_file_name) +logger = logging.getLogger('alembic.env') + + +def get_engine(): + try: + # this works with Flask-SQLAlchemy<3 and Alchemical + return current_app.extensions['migrate'].db.get_engine() + except (TypeError, AttributeError): + # this works with Flask-SQLAlchemy>=3 + return current_app.extensions['migrate'].db.engine + + +def get_engine_url(): + try: + return get_engine().url.render_as_string(hide_password=False).replace( + '%', '%%') + except AttributeError: + return str(get_engine().url).replace('%', '%%') + + +# add your model's MetaData object here +# for 'autogenerate' support +# from myapp import mymodel +# target_metadata = mymodel.Base.metadata +config.set_main_option('sqlalchemy.url', get_engine_url()) +target_db = current_app.extensions['migrate'].db + +# other values from the config, defined by the needs of env.py, +# can be acquired: +# my_important_option = config.get_main_option("my_important_option") +# ... etc. + + +def get_metadata(): + if hasattr(target_db, 'metadatas'): + return target_db.metadatas[None] + return target_db.metadata + + +def run_migrations_offline(): + """Run migrations in 'offline' mode. + + This configures the context with just a URL + and not an Engine, though an Engine is acceptable + here as well. By skipping the Engine creation + we don't even need a DBAPI to be available. + + Calls to context.execute() here emit the given string to the + script output. + + """ + url = config.get_main_option("sqlalchemy.url") + context.configure( + url=url, target_metadata=get_metadata(), literal_binds=True + ) + + with context.begin_transaction(): + context.run_migrations() + + +def run_migrations_online(): + """Run migrations in 'online' mode. + + In this scenario we need to create an Engine + and associate a connection with the context. + + """ + + # this callback is used to prevent an auto-migration from being generated + # when there are no changes to the schema + # reference: http://alembic.zzzcomputing.com/en/latest/cookbook.html + def process_revision_directives(context, revision, directives): + if getattr(config.cmd_opts, 'autogenerate', False): + script = directives[0] + if script.upgrade_ops.is_empty(): + directives[:] = [] + logger.info('No changes in schema detected.') + + conf_args = current_app.extensions['migrate'].configure_args + if conf_args.get("process_revision_directives") is None: + conf_args["process_revision_directives"] = process_revision_directives + + connectable = get_engine() + + with connectable.connect() as connection: + context.configure( + connection=connection, + target_metadata=get_metadata(), + **conf_args + ) + + with context.begin_transaction(): + context.run_migrations() + + +if context.is_offline_mode(): + run_migrations_offline() +else: + run_migrations_online() diff --git a/Sanjana-Easy/Task 3/migrations/script.py.mako b/Sanjana-Easy/Task 3/migrations/script.py.mako new file mode 100644 index 0000000..c95e0ea --- /dev/null +++ b/Sanjana-Easy/Task 3/migrations/script.py.mako @@ -0,0 +1,24 @@ +"""${message} + +Revision ID: ${up_revision} +Revises: ${down_revision | comma,n} +Create Date: ${create_date} + +""" +from alembic import op +import sqlalchemy as sa +${imports if imports else ""} + +# revision identifiers, used by Alembic. +revision = ${repr(up_revision)} +down_revision = ${repr(down_revision)} +branch_labels = ${repr(branch_labels)} +depends_on = ${repr(depends_on)} + + +def upgrade(): + ${upgrades if upgrades else "pass"} + + +def downgrade(): + ${downgrades if downgrades else "pass"} diff --git a/Sanjana-Easy/Task 3/migrations/versions/06fba380cd41_.py b/Sanjana-Easy/Task 3/migrations/versions/06fba380cd41_.py new file mode 100644 index 0000000..4948cca --- /dev/null +++ b/Sanjana-Easy/Task 3/migrations/versions/06fba380cd41_.py @@ -0,0 +1,50 @@ +"""empty message + +Revision ID: 06fba380cd41 +Revises: 3aba37d439b5 +Create Date: 2023-10-12 02:25:59.469198 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '06fba380cd41' +down_revision = '3aba37d439b5' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.create_table('user', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('username', sa.String(length=50), nullable=False), + sa.Column('password', sa.String(length=100), nullable=False), + sa.PrimaryKeyConstraint('id'), + sa.UniqueConstraint('username') + ) + op.drop_table('User') + with op.batch_alter_table('task', schema=None) as batch_op: + batch_op.add_column(sa.Column('user_id', sa.Integer(), nullable=False)) + batch_op.create_foreign_key('fk_task_user', 'user', ['user_id'], ['id']) + + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table('task', schema=None) as batch_op: + batch_op.drop_constraint('fk_task_user', type_='foreignkey') + batch_op.drop_column('user_id') + + op.create_table('User', + sa.Column('id', sa.INTEGER(), nullable=False), + sa.Column('username', sa.VARCHAR(length=50), nullable=False), + sa.Column('password', sa.VARCHAR(length=100), nullable=False), + sa.PrimaryKeyConstraint('id'), + sa.UniqueConstraint('username') + ) + op.drop_table('user') + # ### end Alembic commands ### diff --git a/Sanjana-Easy/Task 3/migrations/versions/2b098398babb_.py b/Sanjana-Easy/Task 3/migrations/versions/2b098398babb_.py new file mode 100644 index 0000000..e0147ad --- /dev/null +++ b/Sanjana-Easy/Task 3/migrations/versions/2b098398babb_.py @@ -0,0 +1,50 @@ +"""empty message + +Revision ID: 2b098398babb +Revises: +Create Date: 2023-10-12 02:14:55.617587 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '2b098398babb' +down_revision = None +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.create_table('user', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('username', sa.String(length=50), nullable=False), + sa.Column('password', sa.String(length=100), nullable=False), + sa.PrimaryKeyConstraint('id'), + sa.UniqueConstraint('username') + ) + op.drop_table('User') + with op.batch_alter_table('task', schema=None) as batch_op: + batch_op.add_column(sa.Column('user_id', sa.Integer(), nullable=False)) + batch_op.create_foreign_key(None, 'user', ['user_id'], ['id']) + + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table('task', schema=None) as batch_op: + batch_op.drop_constraint(None, type_='foreignkey') + batch_op.drop_column('user_id') + + op.create_table('User', + sa.Column('id', sa.INTEGER(), nullable=False), + sa.Column('username', sa.VARCHAR(length=50), nullable=False), + sa.Column('password', sa.VARCHAR(length=100), nullable=False), + sa.PrimaryKeyConstraint('id'), + sa.UniqueConstraint('username') + ) + op.drop_table('user') + # ### end Alembic commands ### diff --git a/Sanjana-Easy/Task 3/migrations/versions/3aba37d439b5_.py b/Sanjana-Easy/Task 3/migrations/versions/3aba37d439b5_.py new file mode 100644 index 0000000..f5b524d --- /dev/null +++ b/Sanjana-Easy/Task 3/migrations/versions/3aba37d439b5_.py @@ -0,0 +1,24 @@ +"""empty message + +Revision ID: 3aba37d439b5 +Revises: 2b098398babb +Create Date: 2023-10-12 02:22:35.853412 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '3aba37d439b5' +down_revision = '2b098398babb' +branch_labels = None +depends_on = None + + +def upgrade(): + pass + + +def downgrade(): + pass diff --git a/Sanjana-Easy/Task 3/migrations/versions/__pycache__/06fba380cd41_.cpython-311.pyc b/Sanjana-Easy/Task 3/migrations/versions/__pycache__/06fba380cd41_.cpython-311.pyc new file mode 100644 index 0000000..66ff04c Binary files /dev/null and b/Sanjana-Easy/Task 3/migrations/versions/__pycache__/06fba380cd41_.cpython-311.pyc differ diff --git a/Sanjana-Easy/Task 3/migrations/versions/__pycache__/2b098398babb_.cpython-311.pyc b/Sanjana-Easy/Task 3/migrations/versions/__pycache__/2b098398babb_.cpython-311.pyc new file mode 100644 index 0000000..f7f938a Binary files /dev/null and b/Sanjana-Easy/Task 3/migrations/versions/__pycache__/2b098398babb_.cpython-311.pyc differ diff --git a/Sanjana-Easy/Task 3/migrations/versions/__pycache__/3aba37d439b5_.cpython-311.pyc b/Sanjana-Easy/Task 3/migrations/versions/__pycache__/3aba37d439b5_.cpython-311.pyc new file mode 100644 index 0000000..09c01f5 Binary files /dev/null and b/Sanjana-Easy/Task 3/migrations/versions/__pycache__/3aba37d439b5_.cpython-311.pyc differ diff --git a/Sanjana-Easy/Task 3/requirements.txt b/Sanjana-Easy/Task 3/requirements.txt new file mode 100644 index 0000000..1dbaede --- /dev/null +++ b/Sanjana-Easy/Task 3/requirements.txt @@ -0,0 +1,7 @@ +alembic==1.13.2 +Flask==3.0.3 +flask_login==0.6.3 +flask_migrate==4.0.7 +flask_sqlalchemy==3.1.1 +SQLAlchemy==2.0.31 +Werkzeug==3.0.3 diff --git a/Sanjana-Easy/Task 3/templates/add_task.html b/Sanjana-Easy/Task 3/templates/add_task.html new file mode 100644 index 0000000..1db97cd --- /dev/null +++ b/Sanjana-Easy/Task 3/templates/add_task.html @@ -0,0 +1,80 @@ + + + + + + + Add Task ➕🏢 + + + + +

Add Task

+ {% with messages = get_flashed_messages() %} + {% if messages %} + + {% endif %} + {% endwith %} +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
#FieldValue
1
2
3
+ +
+ + + + + + + + + + \ No newline at end of file diff --git a/Sanjana-Easy/Task 3/templates/dashboard.html b/Sanjana-Easy/Task 3/templates/dashboard.html new file mode 100644 index 0000000..4a85549 --- /dev/null +++ b/Sanjana-Easy/Task 3/templates/dashboard.html @@ -0,0 +1,81 @@ + + + + + + + Dashboard + + + + + +

Task Dashboard 📟

+ + + {% with messages = get_flashed_messages() %} + {% if messages %} + + {% endif %} + {% endwith %} + + + + + + + + + + + + + + {% for task in tasks %} + + + + + + + + {% endfor %} + +
#TitleDescriptionDue DateActions
{{ task.id }}{{ task.title }}{{ task.description }}{{ task.due_date.strftime('%Y-%m-%d') }} + Edit +
+ +
+
+ + +

Add a Task

+ + +

Logout

+ + + + \ No newline at end of file diff --git a/Sanjana-Easy/Task 3/templates/edit_task.html b/Sanjana-Easy/Task 3/templates/edit_task.html new file mode 100644 index 0000000..4a09c4b --- /dev/null +++ b/Sanjana-Easy/Task 3/templates/edit_task.html @@ -0,0 +1,64 @@ + + + + + + + Edit Task ✖🖊 + + + + + +

Edit Task

+ + + {% with messages = get_flashed_messages() %} + {% if messages %} + + {% endif %} + {% endwith %} + + +
+ + +
+ + +
+ + +
+ +
+ + +

Back to Dashboard

+ + + + \ No newline at end of file diff --git a/Sanjana-Easy/Task 3/templates/login.html b/Sanjana-Easy/Task 3/templates/login.html new file mode 100644 index 0000000..eb13262 --- /dev/null +++ b/Sanjana-Easy/Task 3/templates/login.html @@ -0,0 +1,51 @@ + + + + + + + Login + + + + +

Login

+ {% with messages = get_flashed_messages() %} + {% if messages %} + + {% endif %} + {% endwith %} +
+ + +
+ + +
+ +
+ + + \ No newline at end of file diff --git a/Sanjana-Easy/Task 3/templates/register.html b/Sanjana-Easy/Task 3/templates/register.html new file mode 100644 index 0000000..08354b6 --- /dev/null +++ b/Sanjana-Easy/Task 3/templates/register.html @@ -0,0 +1,60 @@ + + + + + + + Task Manager + + + + + +

Register

+ {% with messages = get_flashed_messages() %} + {% if messages %} + + {% endif %} + {% endwith %} +
+ + +
+ + +
+ + + +
+ + + + + + \ No newline at end of file diff --git a/Sanjana-Easy/Task 4/Task4.py b/Sanjana-Easy/Task 4/Task4.py new file mode 100644 index 0000000..51f06f1 --- /dev/null +++ b/Sanjana-Easy/Task 4/Task4.py @@ -0,0 +1,61 @@ +import pyaudio +import wave +from pydub import AudioSegment + +FRAMES_PER_BUFFER = 3200 +FORMAT = pyaudio.paInt16 +CHANNELS = 1 +RATE = 16000 + +def record_audio(seconds, filename): + p = pyaudio.PyAudio() + stream = p.open(format=FORMAT, channels=CHANNELS, rate=RATE, input=True, frames_per_buffer=FRAMES_PER_BUFFER) + print("Start recording") + frames = [stream.read(FRAMES_PER_BUFFER) for _ in range(int(RATE / FRAMES_PER_BUFFER * seconds))] + print("Recording finished") + stream.stop_stream() + stream.close() + p.terminate() + with wave.open(filename, 'wb') as wf: + wf.setnchannels(CHANNELS) + wf.setsampwidth(p.get_sample_size(FORMAT)) + wf.setframerate(RATE) + wf.writeframes(b''.join(frames)) + +def playback_audio(filename): + with wave.open(filename, 'rb') as wf: + p = pyaudio.PyAudio() + stream = p.open(format=p.get_format_from_width(wf.getsampwidth()), channels=wf.getnchannels(), rate=wf.getframerate(), output=True) + data = wf.readframes(FRAMES_PER_BUFFER) + while data: + stream.write(data) + data = wf.readframes(FRAMES_PER_BUFFER) + stream.stop_stream() + stream.close() + p.terminate() + +def convert_format(input_filename, output_filename): + audio = AudioSegment.from_wav(input_filename) + audio.export(output_filename, format=output_filename.split('.')[-1]) + print(f"Recording saved as {output_filename}") + +def main(): + actions = { + '1': ('Record Audio', lambda: record_audio(int(input("Enter duration of recording in seconds: ")), input("Enter filename to save (with .wav extension): "))), + '2': ('Playback Audio', lambda: playback_audio(input("Enter filename to playback (with .wav extension): "))), + '3': ('Save Audio in Different Format', lambda: convert_format(input("Enter the recorded filename (with .wav extension): "), input("Enter the new filename with desired extension (e.g., recording.mp3): "))), + '4': ('Exit', lambda: exit()) + } + while True: + print("\nVoice Recording Application") + for key, (desc, _) in actions.items(): + print(f"{key}. {desc}") + choice = input("Select an option: ") + action = actions.get(choice) + if action: + action[1]() + else: + print("Invalid choice. Please select again.") + +if __name__ == "__main__": + main() diff --git a/Sanjana-Easy/Task 4/requirements.txt b/Sanjana-Easy/Task 4/requirements.txt new file mode 100644 index 0000000..9785bbf --- /dev/null +++ b/Sanjana-Easy/Task 4/requirements.txt @@ -0,0 +1,2 @@ +PyAudio==0.2.14 +pydub==0.25.1