mirror of
https://github.com/house-of-vanity/libopenanal.git
synced 2025-07-07 05:34:08 +00:00
Pagination
This commit is contained in:
35
database.py
35
database.py
@ -28,12 +28,6 @@ class DataBase:
|
|||||||
sql = "SELECT id FROM word WHERE word = '%s'" % word
|
sql = "SELECT id FROM word WHERE word = '%s'" % word
|
||||||
return self.execute(sql)[0][0]
|
return self.execute(sql)[0][0]
|
||||||
|
|
||||||
'''
|
|
||||||
def get_memes(self, offset=0):
|
|
||||||
sql = "SELECT * FROM `meme` ORDER BY rowid DESC "
|
|
||||||
return self.execute(sql)
|
|
||||||
'''
|
|
||||||
|
|
||||||
def get_user_count(self):
|
def get_user_count(self):
|
||||||
sql = "SELECT count(*) FROM `user`"
|
sql = "SELECT count(*) FROM `user`"
|
||||||
return self.execute(sql)[0]
|
return self.execute(sql)[0]
|
||||||
@ -116,6 +110,35 @@ class DataBase:
|
|||||||
"""
|
"""
|
||||||
return self.execute(sql)
|
return self.execute(sql)
|
||||||
|
|
||||||
|
def get_words(self, page_number=0, limit=20, search=None):
|
||||||
|
offset = page_number * limit
|
||||||
|
if search == None:
|
||||||
|
sql = """
|
||||||
|
SELECT max(date(r.date, 'unixepoch')) as 'last seen',
|
||||||
|
min(date(r.date, 'unixepoch')) as 'first seen',
|
||||||
|
w.word, count(r.word_id) as count, u.username, w.id
|
||||||
|
FROM `relations` r
|
||||||
|
LEFT JOIN `word` w ON w.id = r.word_id
|
||||||
|
LEFT JOIN `user` u ON u.id = r.user_id
|
||||||
|
GROUP BY r.word_id
|
||||||
|
ORDER BY count desc
|
||||||
|
LIMIT %s OFFSET %s
|
||||||
|
""" % (limit, offset)
|
||||||
|
else:
|
||||||
|
sql = """
|
||||||
|
SELECT max(date(r.date, 'unixepoch')) as 'last seen',
|
||||||
|
min(date(r.date, 'unixepoch')) as 'first seen',
|
||||||
|
w.word, count(r.word_id) as count, u.username, w.id
|
||||||
|
FROM `relations` r
|
||||||
|
LEFT JOIN `word` w ON w.id = r.word_id
|
||||||
|
LEFT JOIN `user` u ON u.id = r.user_id
|
||||||
|
WHERE w.word like '%%%s%%'
|
||||||
|
GROUP BY r.word_id
|
||||||
|
ORDER BY count desc
|
||||||
|
LIMIT %s OFFSET %s
|
||||||
|
""" % (search, limit, offset)
|
||||||
|
return self.execute(sql)
|
||||||
|
|
||||||
def get_conf_info(self, conf_id):
|
def get_conf_info(self, conf_id):
|
||||||
if not conf_id[1:].isdigit():
|
if not conf_id[1:].isdigit():
|
||||||
return False
|
return False
|
||||||
|
33
index.py
33
index.py
@ -69,19 +69,22 @@ def conf():
|
|||||||
totals=totals)
|
totals=totals)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/words')
|
@app.route('/words', methods=['GET'])
|
||||||
def words():
|
def words():
|
||||||
totals = {
|
limit = request.args.get('limit', default=20, type=int)
|
||||||
'users': db.get_user_count(),
|
page_number = request.args.get('page_number', default=1, type=int)
|
||||||
'words': db.get_word_count(),
|
search = request.args.get('search', default="", type=str)
|
||||||
'relations': db.get_relations_count(),
|
if search != "":
|
||||||
'confs': db.get_confs_count()
|
#page_number = 1
|
||||||
}
|
words=db.get_words(int(page_number)-1, limit=limit, search=search)
|
||||||
|
else:
|
||||||
|
words=db.get_words(int(page_number)-1, limit=limit)
|
||||||
return render_template(
|
return render_template(
|
||||||
'conf.html',
|
'words.html',
|
||||||
confs=db.get_confs(),
|
words=words,
|
||||||
totals=totals)
|
page_number=int(page_number),
|
||||||
|
limit=limit,
|
||||||
|
search=search)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/overview/conf/<conf_id>')
|
@app.route('/overview/conf/<conf_id>')
|
||||||
@ -210,6 +213,14 @@ def main():
|
|||||||
def datetimeformat(value, format='%H:%M / %d-%m-%Y'):
|
def datetimeformat(value, format='%H:%M / %d-%m-%Y'):
|
||||||
return datetime.datetime.fromtimestamp(value).strftime(format)
|
return datetime.datetime.fromtimestamp(value).strftime(format)
|
||||||
|
|
||||||
|
@app.template_filter('shortener')
|
||||||
|
def shortener(word, limit=20):
|
||||||
|
if len(word) > limit:
|
||||||
|
word = word[0:limit]+'...'
|
||||||
|
else:
|
||||||
|
pass
|
||||||
|
return word
|
||||||
|
|
||||||
|
|
||||||
@app.template_filter('readable_delta')
|
@app.template_filter('readable_delta')
|
||||||
def readable_delta(from_seconds, until_seconds=None):
|
def readable_delta(from_seconds, until_seconds=None):
|
||||||
|
@ -12,11 +12,15 @@
|
|||||||
<a class="nav-link active" href="/conf">Conferences</a>
|
<a class="nav-link active" href="/conf">Conferences</a>
|
||||||
</li>
|
</li>
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link" href="/stat">2ch.hk Stats</a>
|
<a class="nav-link" href="/words">Words</a>
|
||||||
</li>
|
</li>
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link disabled" href="#">Disabled</a>
|
<a class="nav-link" href="/stat">2ch.hk Stats</a>
|
||||||
</li>
|
</li>
|
||||||
|
<!--
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link disabled" href="#">Disabled</a>
|
||||||
|
</li>-->
|
||||||
</ul>
|
</ul>
|
||||||
<br>
|
<br>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
@ -56,4 +60,4 @@
|
|||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% block scripts %}
|
{% block scripts %}
|
||||||
{{ super() }}
|
{{ super() }}
|
||||||
{% endblock %}
|
{% endblock %}
|
@ -12,10 +12,10 @@
|
|||||||
<a class="nav-link" href="/conf">Conferences</a>
|
<a class="nav-link" href="/conf">Conferences</a>
|
||||||
</li>
|
</li>
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link" href="/stat">2ch.hk Stats</a>
|
<a class="nav-link" href="/words">Words</a>
|
||||||
</li>
|
</li>
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link disabled" href="#">Disabled</a>
|
<a class="nav-link" href="/stat">2ch.hk Stats</a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<br>
|
<br>
|
||||||
|
@ -12,10 +12,10 @@
|
|||||||
<a class="nav-link" href="/conf">Conferences</a>
|
<a class="nav-link" href="/conf">Conferences</a>
|
||||||
</li>
|
</li>
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link" href="/stat">2ch.hk Stats</a>
|
<a class="nav-link" href="/words">Words</a>
|
||||||
</li>
|
</li>
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link disabled" href="#">Disabled</a>
|
<a class="nav-link" href="/stat">2ch.hk Stats</a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<br>
|
<br>
|
||||||
@ -46,7 +46,7 @@
|
|||||||
<b>First message: </b>{{ user_info.first_date }}<br>
|
<b>First message: </b>{{ user_info.first_date }}<br>
|
||||||
<b>Last message: </b>{{ user_info.last_message }}<br>
|
<b>Last message: </b>{{ user_info.last_message }}<br>
|
||||||
<b>Days known: </b>{{ user_info.day_known }}<br>
|
<b>Days known: </b>{{ user_info.day_known }}<br>
|
||||||
<b>Word said: </b>{{ user_info.word_count }}<br>
|
<b>Words said: </b>{{ user_info.word_count }}<br>
|
||||||
<b>Messages sent: </b>{{ user_info.messages }}<br>
|
<b>Messages sent: </b>{{ user_info.messages }}<br>
|
||||||
<b>Words per day: </b>{{ '%0.2f'| format((user_info.word_count / user_info.day_known)|float) }}<br>
|
<b>Words per day: </b>{{ '%0.2f'| format((user_info.word_count / user_info.day_known)|float) }}<br>
|
||||||
<b>Words per message: </b>~{{ '%0.2f'| format(user_info.avg|float) }}<br>
|
<b>Words per message: </b>~{{ '%0.2f'| format(user_info.avg|float) }}<br>
|
||||||
|
142
templates/words.html
Normal file
142
templates/words.html
Normal file
@ -0,0 +1,142 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
{% block head %}
|
||||||
|
{{ super() }}
|
||||||
|
{% endblock %}
|
||||||
|
{% block content %}
|
||||||
|
{{ super() }}
|
||||||
|
<ul class="nav nav-pills">
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" href="/">Users</a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" href="/conf">Conferences</a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link active" href="/words">Words</a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" href="/stat">2ch.hk Stats</a>
|
||||||
|
</li>
|
||||||
|
<!--
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link disabled" href="#">Disabled</a>
|
||||||
|
</li>-->
|
||||||
|
</ul>
|
||||||
|
<br>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-sm">
|
||||||
|
<form action="/words" method="GET">
|
||||||
|
<div class="form-row">
|
||||||
|
<div class="col-sm-5 my-1">
|
||||||
|
<div class="input-group">
|
||||||
|
<div class="input-group-prepend">
|
||||||
|
<div class="input-group-text">Limit</div>
|
||||||
|
</div>
|
||||||
|
<input type="number" min="1" max="1000" class="form-control" id='limit' name="limit" value="{{ limit }}">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-auto my-1">
|
||||||
|
<button type="submit" class="btn btn-primary">✔</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-sm">
|
||||||
|
<div class="form-row">
|
||||||
|
<div class="col-auto my-1">
|
||||||
|
<button type="button" class="btn btn-primary" onclick='scroll_page(parseInt(document.getElementById ( "page_counter" ).value, 10)-1)'>🡄</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-sm-3 my-1">
|
||||||
|
<input type="number" min="1" class="form-control" name="page_number" id="page_counter" value="{{ page_number }}">
|
||||||
|
</div>
|
||||||
|
<div class="col-auto my-1">
|
||||||
|
<button type="button" class="btn btn-primary" onclick='scroll_page(parseInt(document.getElementById ( "page_counter" ).value, 10)+1)'>🡆</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-sm">
|
||||||
|
<div class="form-row">
|
||||||
|
<div class="col-sm-9 my-1">
|
||||||
|
<div class="input-group">
|
||||||
|
<div class="input-group-prepend">
|
||||||
|
<div class="input-group-text">Search</div>
|
||||||
|
</div>
|
||||||
|
<input type="text" class="form-control" name="search" value="{{ search }}">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-auto my-1">
|
||||||
|
<button type="submit" class="btn btn-primary">🡆</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<table class="table table-hover table-sm">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th scope="col">#</th>
|
||||||
|
<th scope="col">Word</th>
|
||||||
|
<th scope="col">id</th>
|
||||||
|
<th scope="col">Added</th>
|
||||||
|
<th scope="col">Last seen</th>
|
||||||
|
<th scope="col">Said</th>
|
||||||
|
<th scope="col">Added by</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for word in words %}
|
||||||
|
<tr>
|
||||||
|
<th scope="row">{{ loop.index + limit * (page_number-1) }}</th>
|
||||||
|
<td><div class="col-2"><a href="/overview/word/{{word.4}}">{{ word.2|shortener() }}</a></div></td>
|
||||||
|
<td><a class="badge badge-dark " href="/overview/word/{{word.4}}">{{ word.5 }}</a></td>
|
||||||
|
<td>{{ word.1 }}</td>
|
||||||
|
<td>{{ word.0 }}</td>
|
||||||
|
<td>{{ word.3 }}</td>
|
||||||
|
<td>{{ word.4 }}</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
function scroll_page(page) {
|
||||||
|
location.href = URL_add_parameter(location.href, 'page_number', page);
|
||||||
|
}
|
||||||
|
function change_limit(limit) {
|
||||||
|
location.href = URL_add_parameter(location.href, 'limit', limit);
|
||||||
|
}
|
||||||
|
function start_search(word) {
|
||||||
|
location.href = URL_add_parameter(location.href, 'search', word);
|
||||||
|
}
|
||||||
|
function URL_add_parameter(url, param, value) {
|
||||||
|
var hash = {};
|
||||||
|
var parser = document.createElement('a');
|
||||||
|
|
||||||
|
parser.href = url;
|
||||||
|
|
||||||
|
var parameters = parser.search.split(/\?|&/);
|
||||||
|
|
||||||
|
for (var i = 0; i < parameters.length; i++) {
|
||||||
|
if (!parameters[i])
|
||||||
|
continue;
|
||||||
|
|
||||||
|
var ary = parameters[i].split('=');
|
||||||
|
hash[ary[0]] = ary[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
hash[param] = value;
|
||||||
|
|
||||||
|
var list = [];
|
||||||
|
Object.keys(hash).forEach(function (key) {
|
||||||
|
list.push(key + '=' + hash[key]);
|
||||||
|
});
|
||||||
|
|
||||||
|
parser.search = '?' + list.join('&');
|
||||||
|
return parser.href;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
{% endblock %}
|
||||||
|
{% block scripts %}
|
||||||
|
{{ super() }}
|
||||||
|
{% endblock %}
|
Reference in New Issue
Block a user