diff --git a/database.py b/database.py index fe9e2fe..21bf874 100644 --- a/database.py +++ b/database.py @@ -28,12 +28,6 @@ class DataBase: sql = "SELECT id FROM word WHERE word = '%s'" % word 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): sql = "SELECT count(*) FROM `user`" return self.execute(sql)[0] @@ -116,6 +110,35 @@ class DataBase: """ 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): if not conf_id[1:].isdigit(): return False diff --git a/index.py b/index.py index 5a2dc67..45a8aea 100644 --- a/index.py +++ b/index.py @@ -69,19 +69,22 @@ def conf(): totals=totals) -@app.route('/words') +@app.route('/words', methods=['GET']) def words(): - totals = { - 'users': db.get_user_count(), - 'words': db.get_word_count(), - 'relations': db.get_relations_count(), - 'confs': db.get_confs_count() - } - + limit = request.args.get('limit', default=20, type=int) + page_number = request.args.get('page_number', default=1, type=int) + search = request.args.get('search', default="", type=str) + if search != "": + #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( - 'conf.html', - confs=db.get_confs(), - totals=totals) + 'words.html', + words=words, + page_number=int(page_number), + limit=limit, + search=search) @app.route('/overview/conf/') @@ -210,6 +213,14 @@ def main(): def datetimeformat(value, format='%H:%M / %d-%m-%Y'): 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') def readable_delta(from_seconds, until_seconds=None): diff --git a/templates/conf.html b/templates/conf.html index bc199b3..f8b83f7 100644 --- a/templates/conf.html +++ b/templates/conf.html @@ -12,11 +12,15 @@ Conferences +
@@ -56,4 +60,4 @@ {% endblock %} {% block scripts %} {{ super() }} -{% endblock %} +{% endblock %} \ No newline at end of file diff --git a/templates/index.html b/templates/index.html index 63da59e..f2c53b6 100644 --- a/templates/index.html +++ b/templates/index.html @@ -12,10 +12,10 @@ Conferences
diff --git a/templates/user.html b/templates/user.html index e717b16..8843e48 100644 --- a/templates/user.html +++ b/templates/user.html @@ -12,10 +12,10 @@ Conferences
@@ -46,7 +46,7 @@ First message: {{ user_info.first_date }}
Last message: {{ user_info.last_message }}
Days known: {{ user_info.day_known }}
- Word said: {{ user_info.word_count }}
+ Words said: {{ user_info.word_count }}
Messages sent: {{ user_info.messages }}
Words per day: {{ '%0.2f'| format((user_info.word_count / user_info.day_known)|float) }}
Words per message: ~{{ '%0.2f'| format(user_info.avg|float) }}
diff --git a/templates/words.html b/templates/words.html new file mode 100644 index 0000000..51a4657 --- /dev/null +++ b/templates/words.html @@ -0,0 +1,142 @@ +{% extends "base.html" %} +{% block head %} +{{ super() }} +{% endblock %} +{% block content %} +{{ super() }} + +
+
+
+
+
+
+
+
+
Limit
+
+ +
+
+
+ +
+
+
+
+
+
+ +
+ +
+ +
+
+ +
+
+
+
+
+
+
+
+
Search
+
+ +
+
+
+ +
+
+ +
+
+ + + + + + + + + + + + + + + {% for word in words %} + + + + + + + + + + {% endfor %} + +
#WordidAddedLast seenSaidAdded by
{{ loop.index + limit * (page_number-1) }}{{ word.5 }}{{ word.1 }}{{ word.0 }}{{ word.3 }}{{ word.4 }}
+ + +{% endblock %} +{% block scripts %} +{{ super() }} +{% endblock %} \ No newline at end of file