Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task 3 #69

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Binary file added FLASK/__pycache__/app.cpython-310.pyc
Binary file not shown.
56 changes: 56 additions & 0 deletions Task-3/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
from flask import Flask, render_template, request
from flask_paginate import Pagination, get_page_args
import pymongo

app = Flask(__name__)


@app.route('/')
def entry_point():
return render_template('homepage.html')


@app.route('/search_results')
def search_results():
connect_url = 'mongodb://127.0.0.1:27017/'

client = pymongo.MongoClient(connect_url, connect=False)

db = client.info

search_string = request.args.get('search')

query = db.search_info.find(
{'$text': {'$search': search_string, '$caseSensitive': False}})

search_result = []

for doc in query:
exist = False
for result in search_result:
if result['title'] == doc['title'] or result['url'] == doc['url']:
exist = True
break

if exist == False:
search_result.append(doc)

page, per_page, offset = get_page_args(page_parameter='page',
per_page_parameter='per_page')

total = len(search_result)

pagination = Pagination(page=page, per_page=per_page, total=total,
css_framework='bootstrap4')

return render_template('search.html',
search_result=search_result[offset:offset+per_page],
page=page,
per_page=per_page,
pagination=pagination,
search_string=search_string
)


if __name__ == '__main__':
app.run(debug=True)
Binary file added Task-3/static/images/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions Task-3/templates/homepage.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{% extends 'index.html' %}

{% block content %}
<div class="col">


<div class="col mt-5">
<img src="{{url_for('static', filename='./images/logo.png')}}" class="mx-auto d-block"
style="width: 25%; height: 25%;">
<h1 style="color:rgb(51, 143, 143); text-align:center;font-family: 'Times New Roman', Times, serif;margin-top: 15px;padding: 15px;"
class="mt-2"><b>GLUGLE</b></h2>
</div>


<form class="mt-5 container" name="search" style="width: 50%" action="/search_results">
<div class="col-6 mx-auto input-group">
<input type="text" class="form-control" name="search" placeholder="search...">
<button type="submit" class="btn btn-success">Search</button>
</div>
</form>
</div>
{% endblock %}
37 changes: 37 additions & 0 deletions Task-3/templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<!doctype html>
<html lang="en">

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

<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-F3w7mX95PdgyTmZZMECAngseQB83DfGTowi0iMjiWaeVhAn4FJkqJByhZMI3AhiU" crossorigin="anonymous">

<style>
.form-control:focus {
border-color: #43971b;
box-shadow: 0px 1px 1px rgba(170, 71, 71, 0.075) inset, 0px 0px 8px rgba(255, 100, 255, 0.5);
}

.dropdown {
float: left;
}
</style>

<title>Glugle</title>
</head>

<body style="background-color: rgb(113, 172, 108);">
{% block content %}{% endblock %}


<!-- Option 1: Bootstrap Bundle with Popper -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
integrity="sha384-/bQdsTh/da6pkI1MST/rWKFNjaCP5gBSY4sEBT38Q/9RBh9AH40zEOg7Hlq2THRZ"
crossorigin="anonymous"></script>
</body>

</html>
40 changes: 40 additions & 0 deletions Task-3/templates/search.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{% extends 'index.html' %}

{% block content %}

<div class="container">
<form class="mt-5 container" name="search" style="width: 50%" action="/search_results">
<div class="col-6 mx-auto input-group">
<input type="text" class="form-control" name="search" placeholder="search...">
<button type="submit" class="btn btn-success">Search</button>
</div>
</form>

<div class="container mx-5 mt-5">
<p style="color: teal;"><b>Search result for '{{search_string}}'</b></p>
</div>

{% if search_result %}
{% for link in search_result %}
<div class="container mt-3" style="width:90%">

<div class="col">
<strong><a href="{{ link.url }}" target="_ blank">{{ link.title }}</a></strong>
</div>

<div class="col">
<a href="{{ link.url }}" target="_blank">{{ link.url }}</a>
<p>{{ link.description[:300] }}...</p>
</div>
</div>
{% endfor %}
{% else %}
<b>No results found</b>
{% endif %}

<div class="col mb-5 mt-2 text-center">
{{pagination.links}}
</div>
</div>

{% endblock %}