Skip to content
This repository was archived by the owner on May 25, 2022. It is now read-only.

Commit 57ad6d9

Browse files
authored
Merge pull request #30 from Mitesh2499/master
Added Todo App with Flask Added Links from Webpage Image Watermark
2 parents f322d7f + a1ed9af commit 57ad6d9

File tree

9 files changed

+279
-0
lines changed

9 files changed

+279
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import requests as rq
2+
from bs4 import BeautifulSoup
3+
4+
url = input("Enter Link")
5+
data = rq.get(url)
6+
soup = BeautifulSoup(data.text, "html.parser")
7+
links = []
8+
for link in soup.find_all("a"):
9+
links.append(link.get("href"))
10+
11+
print(links[:10])

projects/Todo app/Readme.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Todo App using flask
2+
## Perform Operation like
3+
1. Add Task
4+
2. Delete Task
5+
3. Update Task
6+
7+
# To run app
8+
- Create virtual Environment
9+
- Install requirements
10+
`pip install requirements.txt`
11+
- run app
12+
`py app.py`

projects/Todo app/app.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
from flask import Flask, render_template,url_for, request, redirect
2+
from flask_sqlalchemy import SQLAlchemy
3+
from datetime import datetime
4+
5+
app = Flask(__name__)
6+
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///test.db'
7+
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
8+
db = SQLAlchemy(app)
9+
10+
11+
12+
13+
14+
15+
class Todo(db.Model):
16+
id=db.Column(db.Integer, primary_key=True)
17+
content=db.Column(db.String(200),nullable=False)
18+
completed=db.Column(db.Integer,default=0)
19+
pub_date = db.Column(db.DateTime, nullable=False,
20+
default=datetime.utcnow)
21+
def __repr__(self):
22+
return '<Task %r>'%self.id
23+
24+
25+
26+
27+
28+
29+
@app.route('/',methods=['POST','GET'])
30+
def index():
31+
if request.method=="POST":
32+
task_content= request.form['task']
33+
new_task=Todo(content=task_content)
34+
35+
try:
36+
db.session.add(new_task)
37+
db.session.commit()
38+
return redirect('/')
39+
except:
40+
return 'There is an issue'
41+
else:
42+
tasks=Todo.query.order_by(Todo.pub_date).all()
43+
return render_template('index.html',tasks=tasks)
44+
45+
@app.route('/delete/<int:id>')
46+
def delete(id):
47+
task=Todo.query.get_or_404(id)
48+
try:
49+
db.session.delete(task)
50+
db.session.commit()
51+
return redirect('/')
52+
except:
53+
return "This is an Problem while deleting"
54+
55+
@app.route('/update/<int:id>',methods=['POST','GET'])
56+
def update(id):
57+
task=Todo.query.get_or_404(id)
58+
if request.method=="POST":
59+
task.content= request.form['task']
60+
61+
62+
try:
63+
64+
db.session.commit()
65+
return redirect('/')
66+
except:
67+
return 'There is an issue'
68+
else:
69+
tasks=Todo.query.order_by(Todo.pub_date).all()
70+
71+
return render_template('index.html', update_task=task,tasks=tasks)
72+
73+
74+
75+
76+
if __name__=="__main__":
77+
app.run(debug=True)

projects/Todo app/requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
flask
2+
flask_sqlalchemy
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
body {
2+
margin: 0;
3+
padding: 0;
4+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<!doctype html>
2+
<html lang="en">
3+
4+
<head>
5+
<!-- Required meta tags -->
6+
<meta charset="utf-8">
7+
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
8+
9+
<!-- Bootstrap CSS -->
10+
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
11+
integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
12+
<link rel="stylesheet" href="{{ url_for('static',filename='css/style.css') }}">
13+
<title>TODO App</title>
14+
{% block head %}
15+
{% endblock %}
16+
</head>
17+
18+
<body>
19+
<div class="container py-3 my-3">
20+
{% block body %}
21+
{% endblock %}
22+
</div>
23+
24+
25+
<!-- Optional JavaScript -->
26+
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
27+
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"
28+
integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous">
29+
</script>
30+
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"
31+
integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous">
32+
</script>
33+
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"
34+
integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous">
35+
</script>
36+
</body>
37+
38+
</html>
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
{% extends 'base.html' %}
2+
{% block head %}
3+
4+
{% endblock %}
5+
{% block body %}
6+
<h2 class="text-center">Todo Webapp</h2>
7+
<div class="container justify-content-center text-center py-3 my-3">
8+
<form action="" method="post">
9+
<div class="form-group">
10+
{% if update_task %}
11+
12+
<input type="text" name="task" id="task" value="{{ update_task.content }}" class="form-control-sm">
13+
<input type="submit" value="Update task" class="btn btn-info">
14+
{% else %}
15+
16+
<input type="text" name="task" id="task">
17+
<input type="submit" value="Add task" class="btn btn-primary" class="form-control-sm">
18+
{% endif %}
19+
20+
21+
22+
</div>
23+
24+
25+
</form>
26+
</div>
27+
<div class="container">
28+
29+
{% if tasks %}
30+
<table class="table">
31+
<thead>
32+
<tr>
33+
34+
<th scope="col">Task</th>
35+
<th scope="col">Date</th>
36+
37+
<th scope="col">Operation</th>
38+
</tr>
39+
</thead>
40+
<tbody>
41+
{% for task in tasks %}
42+
<tr>
43+
44+
<td>{{ task.content }}</td>
45+
<td>{{ task.pub_date.date() }}</td>
46+
<td>
47+
48+
{% if update_task %}
49+
{% if not update_task.id==task.id %}
50+
<a href="update/{{ task.id }}" class="btn btn-info">Update</a>
51+
<a href="delete/{{ task.id }}" class="btn btn-danger">Delete</a>
52+
{% endif %}
53+
{% else %}
54+
55+
<a href="update/{{ task.id }}" class="btn btn-info">Update</a>
56+
<a href="delete/{{ task.id }}" class="btn btn-danger">Delete</a>
57+
58+
{% endif %}
59+
60+
61+
62+
63+
64+
</td>
65+
</tr>
66+
67+
68+
{% endfor %}
69+
70+
71+
</tbody>
72+
</table>
73+
{% else %}
74+
<p class="text-center">There is no task !!</p>
75+
{% endif %}
76+
77+
78+
79+
</div>
80+
81+
82+
{% endblock %}

projects/Todo app/test.db

8 KB
Binary file not shown.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import os
2+
from PIL import Image
3+
from PIL import ImageFilter
4+
5+
6+
def watermark_photo(input_image_path, output_image_path, watermark_image_path):
7+
8+
base_image = Image.open(input_image_path)
9+
watermark = Image.open(watermark_image_path)
10+
# add watermark to your image
11+
position = base_image.size
12+
13+
watermark_size = watermark.size
14+
15+
newsize = int(position[0] * 8 / 100), int(position[0] * 8 / 100)
16+
17+
watermark = watermark.resize(newsize)
18+
# Blur If Needed
19+
# watermark = watermark.filter(ImageFilter.BoxBlur(2))
20+
new_position = position[0] - newsize[0] - 20, position[1] - newsize[1] - 20
21+
22+
transparent = Image.new(mode="RGBA", size=position, color=(0, 0, 0, 0))
23+
# Create a new transparent image
24+
transparent.paste(base_image, (0, 0))
25+
# paste the original image
26+
27+
transparent.paste(watermark, new_position, mask=watermark)
28+
# paste the watermark image
29+
image_mode = base_image.mode
30+
if image_mode == "RGB":
31+
transparent = transparent.convert(image_mode)
32+
else:
33+
transparent = transparent.convert("P")
34+
transparent.save(output_image_path, optimize=True, quality=100)
35+
print("Saving " + output_image_path + " ...")
36+
37+
38+
folder = input("Enter Folder Path : ")
39+
40+
watermark = input("Enter Watermark Path : ")
41+
42+
os.chdir(folder)
43+
files = os.listdir(os.getcwd())
44+
45+
if not os.path.isdir("output"):
46+
os.mkdir("output")
47+
48+
c = 1
49+
for f in files:
50+
if os.path.isfile(os.path.abspath(f)):
51+
if f.endswith(".png") or f.endswith(".jpg"):
52+
watermark_photo(f, "output/" + f, watermark)
53+

0 commit comments

Comments
 (0)