Skip to content
This repository was archived by the owner on May 25, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
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
11 changes: 11 additions & 0 deletions projects/All Links from given Webpage/get_links.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import requests as rq
from bs4 import BeautifulSoup

url = input("Enter Link")
data = rq.get(url)
soup = BeautifulSoup(data.text, "html.parser")
links = []
for link in soup.find_all("a"):
links.append(link.get("href"))

print(links[:10])
12 changes: 12 additions & 0 deletions projects/Todo app/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Todo App using flask
## Perform Operation like
1. Add Task
2. Delete Task
3. Update Task

# To run app
- Create virtual Environment
- Install requirements
`pip install requirements.txt`
- run app
`py app.py`
77 changes: 77 additions & 0 deletions projects/Todo app/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
from flask import Flask, render_template,url_for, request, redirect
from flask_sqlalchemy import SQLAlchemy
from datetime import datetime

app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///test.db'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db = SQLAlchemy(app)






class Todo(db.Model):
id=db.Column(db.Integer, primary_key=True)
content=db.Column(db.String(200),nullable=False)
completed=db.Column(db.Integer,default=0)
pub_date = db.Column(db.DateTime, nullable=False,
default=datetime.utcnow)
def __repr__(self):
return '<Task %r>'%self.id






@app.route('/',methods=['POST','GET'])
def index():
if request.method=="POST":
task_content= request.form['task']
new_task=Todo(content=task_content)

try:
db.session.add(new_task)
db.session.commit()
return redirect('/')
except:
return 'There is an issue'
else:
tasks=Todo.query.order_by(Todo.pub_date).all()
return render_template('index.html',tasks=tasks)

@app.route('/delete/<int:id>')
def delete(id):
task=Todo.query.get_or_404(id)
try:
db.session.delete(task)
db.session.commit()
return redirect('/')
except:
return "This is an Problem while deleting"

@app.route('/update/<int:id>',methods=['POST','GET'])
def update(id):
task=Todo.query.get_or_404(id)
if request.method=="POST":
task.content= request.form['task']


try:

db.session.commit()
return redirect('/')
except:
return 'There is an issue'
else:
tasks=Todo.query.order_by(Todo.pub_date).all()

return render_template('index.html', update_task=task,tasks=tasks)




if __name__=="__main__":
app.run(debug=True)
2 changes: 2 additions & 0 deletions projects/Todo app/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
flask
flask_sqlalchemy
4 changes: 4 additions & 0 deletions projects/Todo app/static/css/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
body {
margin: 0;
padding: 0;
}
38 changes: 38 additions & 0 deletions projects/Todo app/templates/base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<!doctype html>
<html lang="en">

<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<link rel="stylesheet" href="{{ url_for('static',filename='css/style.css') }}">
<title>TODO App</title>
{% block head %}
{% endblock %}
</head>

<body>
<div class="container py-3 my-3">
{% block body %}
{% endblock %}
</div>


<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"
integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous">
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"
integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous">
</script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"
integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous">
</script>
</body>

</html>
82 changes: 82 additions & 0 deletions projects/Todo app/templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
{% extends 'base.html' %}
{% block head %}

{% endblock %}
{% block body %}
<h2 class="text-center">Todo Webapp</h2>
<div class="container justify-content-center text-center py-3 my-3">
<form action="" method="post">
<div class="form-group">
{% if update_task %}

<input type="text" name="task" id="task" value="{{ update_task.content }}" class="form-control-sm">
<input type="submit" value="Update task" class="btn btn-info">
{% else %}

<input type="text" name="task" id="task">
<input type="submit" value="Add task" class="btn btn-primary" class="form-control-sm">
{% endif %}



</div>


</form>
</div>
<div class="container">

{% if tasks %}
<table class="table">
<thead>
<tr>

<th scope="col">Task</th>
<th scope="col">Date</th>

<th scope="col">Operation</th>
</tr>
</thead>
<tbody>
{% for task in tasks %}
<tr>

<td>{{ task.content }}</td>
<td>{{ task.pub_date.date() }}</td>
<td>

{% if update_task %}
{% if not update_task.id==task.id %}
<a href="update/{{ task.id }}" class="btn btn-info">Update</a>
<a href="delete/{{ task.id }}" class="btn btn-danger">Delete</a>
{% endif %}
{% else %}

<a href="update/{{ task.id }}" class="btn btn-info">Update</a>
<a href="delete/{{ task.id }}" class="btn btn-danger">Delete</a>

{% endif %}





</td>
</tr>


{% endfor %}


</tbody>
</table>
{% else %}
<p class="text-center">There is no task !!</p>
{% endif %}



</div>


{% endblock %}
Binary file added projects/Todo app/test.db
Binary file not shown.
53 changes: 53 additions & 0 deletions projects/image watermark/watermark.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import os
from PIL import Image
from PIL import ImageFilter


def watermark_photo(input_image_path, output_image_path, watermark_image_path):

base_image = Image.open(input_image_path)
watermark = Image.open(watermark_image_path)
# add watermark to your image
position = base_image.size

watermark_size = watermark.size

newsize = int(position[0] * 8 / 100), int(position[0] * 8 / 100)

watermark = watermark.resize(newsize)
# Blur If Needed
# watermark = watermark.filter(ImageFilter.BoxBlur(2))
new_position = position[0] - newsize[0] - 20, position[1] - newsize[1] - 20

transparent = Image.new(mode="RGBA", size=position, color=(0, 0, 0, 0))
# Create a new transparent image
transparent.paste(base_image, (0, 0))
# paste the original image

transparent.paste(watermark, new_position, mask=watermark)
# paste the watermark image
image_mode = base_image.mode
if image_mode == "RGB":
transparent = transparent.convert(image_mode)
else:
transparent = transparent.convert("P")
transparent.save(output_image_path, optimize=True, quality=100)
print("Saving " + output_image_path + " ...")


folder = input("Enter Folder Path : ")

watermark = input("Enter Watermark Path : ")

os.chdir(folder)
files = os.listdir(os.getcwd())

if not os.path.isdir("output"):
os.mkdir("output")

c = 1
for f in files:
if os.path.isfile(os.path.abspath(f)):
if f.endswith(".png") or f.endswith(".jpg"):
watermark_photo(f, "output/" + f, watermark)