Introduction
Introduction Statistics Contact Development Disclaimer Help
refactor of search page - linuxgaming - Linux gaming aggregate tool, built to t…
Log
Files
Refs
README
---
commit 79554a6eb94acc3fcf37bec7ee6c8fffa97a2b22
parent e6c2cbf8aeee89296942f9e7974dba10a6921f9e
Author: Jay Scott <[email protected]>
Date: Wed, 18 Jul 2018 12:02:46 +0100
refactor of search page
Diffstat:
M TODO.md | 7 ++++---
M linuxgaming/__init__.py | 8 +++-----
A linuxgaming/database.py | 15 +++++++++++++++
M linuxgaming/search.py | 87 +++++++----------------------…
M linuxgaming/templates/pages/search… | 17 +----------------
5 files changed, 41 insertions(+), 93 deletions(-)
---
diff --git a/TODO.md b/TODO.md
@@ -3,7 +3,7 @@
## pre 1.0
- - Add better searching
+
- Refactor code
@@ -13,4 +13,5 @@
- Move updates to AWS Lambda function
- Add API
- Add Itch.io games
- - Add Steam games
-\ No newline at end of file
+ - Add Steam games
+ - Add better searching
+\ No newline at end of file
diff --git a/linuxgaming/__init__.py b/linuxgaming/__init__.py
@@ -8,6 +8,7 @@ import dateutil.parser
from . import update
from . import details
from . import search
+from . import database
compress = Compress()
@@ -34,11 +35,8 @@ def create_app():
@app.route("/")
def home():
-
- today = datetime.now()
- all_data = mongo.db.items.find(
- {"date": {'$gte': today - timedelta(hours=24)}}).sort('date', -1)
- return render_template('pages/home.html', entries=all_data)
+ result = database.db_search({"date": {'$gte': datetime.now() - timedel…
+ return render_template('pages/home.html', entries=result)
@app.errorhandler(500)
def internal_error(error):
diff --git a/linuxgaming/database.py b/linuxgaming/database.py
@@ -0,0 +1,15 @@
+from flask import current_app
+from pprint import pprint
+
+
+def db_search(query={}):
+
+ try:
+ d = current_app.mongo.db.items.find(
+ query
+ ).sort('date', -1)
+ except pymongo.errors.OperationFailure:
+ print("DB Error")
+ return False
+
+ return d
diff --git a/linuxgaming/search.py b/linuxgaming/search.py
@@ -1,77 +1,26 @@
from flask import (
Blueprint,
+ flash,
+ redirect,
+ url_for,
render_template,
current_app)
bp = Blueprint('search', __name__, url_prefix='/search')
[email protected]("/twitch", methods=('GET', 'POST'))
-def twitch():
-
- all_data = current_app.mongo.db.items.find(
- {"type": "twitch"}).sort('date', -1)
- return render_template(
- 'pages/search.html',
- entries=all_data,
- count=all_data.count(),
- source="twitch")
-
-
[email protected]("/youtube", methods=('GET', 'POST'))
-def youtube():
-
- all_data = current_app.mongo.db.items.find(
- {"type": "youtube"}).sort('date', -1)
- return render_template(
- 'pages/search.html',
- entries=all_data,
- count=all_data.count(),
- source="youtube")
-
-
[email protected]("/article", methods=('GET', 'POST'))
-def article():
-
- all_data = current_app.mongo.db.items.find(
- {"type": "article"}).sort('date', -1)
- return render_template(
- 'pages/search.html',
- entries=all_data,
- count=all_data.count(),
- source="articles")
-
-
[email protected]("/podcast", methods=('GET', 'POST'))
-def podcast():
-
- all_data = current_app.mongo.db.items.find(
- {"type": "podcast"}).sort('date', -1)
- return render_template(
- 'pages/search.html',
- entries=all_data,
- count=all_data.count(),
- source="podcasts")
-
-
[email protected]("/gog", methods=('GET', 'POST'))
-def gog():
-
- all_data = current_app.mongo.db.items.find(
- {"name": "gog"}).sort('date', -1)
- return render_template(
- 'pages/search.html',
- entries=all_data,
- count=all_data.count(),
- source="gog")
-
-
[email protected]("/allthethings", methods=('GET', 'POST'))
-def allthethings():
-
- all_data = current_app.mongo.db.items.find().sort('date', -1)
- return render_template(
- 'pages/search.html',
- entries=all_data,
- count=all_data.count(),
- source="of all the things")
[email protected]("/<path:path>", methods=('GET', 'POST'))
+def test(path):
+
+ pages = ['gog', 'twitch', 'youtube', 'article', 'podcast', 'allthethings']
+ if any(x in path for x in pages):
+ result = current_app.mongo.db.items.find(
+ {"type": path}).sort('date', -1)
+ return render_template(
+ 'pages/search.html',
+ entries=result,
+ count=result.count())
+ else:
+ flash('1337 Hacks in progress...')
+ current_app.logger.info('Manual search probe %s', path)
+ return redirect(url_for('home'))
diff --git a/linuxgaming/templates/pages/search.html b/linuxgaming/templates/pa…
@@ -3,23 +3,8 @@
{% block content %}
-{% with messages = get_flashed_messages() %}
- {% if messages %}
- {% for message in messages %}
- <div class="ui massive red icon message">
- <i class="spinner loading icon"></i>
- <div class="content">
- <div class="header">
- {{ message }}
- </div>
- </div>
- </div>
- {% endfor %}
- {% endif %}
-{% endwith %}
-
<div class="ui horizontal divider">
- {{ count }} {{ source }} Results
+ {{ count }} Results
</div>
<table class="ui striped very compact small olive table">
You are viewing proxied material from jay.scot. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.