mirror of
https://github.com/house-of-vanity/libopenanal.git
synced 2025-08-21 16:07:16 +00:00
2ch statistic page has been fixed and improved.
This commit is contained in:
48
index.py
48
index.py
@@ -1,7 +1,9 @@
|
||||
import datetime
|
||||
import logging
|
||||
|
||||
import os
|
||||
import requests
|
||||
import time
|
||||
|
||||
from flask import Flask, request, send_from_directory
|
||||
from flask import render_template
|
||||
|
||||
@@ -35,7 +37,7 @@ def serve_static(path):
|
||||
return send_from_directory('static', path)
|
||||
|
||||
|
||||
@app.route('/')
|
||||
@app.route('/', methods=['GET', 'POST'])
|
||||
def index():
|
||||
order = request.args.get('order', default='id', type=str)
|
||||
sorting = request.args.get('sorting', default='ASC', type=str)
|
||||
@@ -136,6 +138,7 @@ def stat():
|
||||
sorting=sorting,
|
||||
posts=posts,
|
||||
threads=sorted_threads,
|
||||
now=datetime.datetime.now().strftime('%s'),
|
||||
)
|
||||
|
||||
|
||||
@@ -143,5 +146,46 @@ def main():
|
||||
app.run(host=flask_host, port=flask_port)
|
||||
|
||||
|
||||
@app.template_filter('datetimeformat')
|
||||
def datetimeformat(value, format='%H:%M / %d-%m-%Y'):
|
||||
return datetime.datetime.fromtimestamp(value).strftime(format)
|
||||
|
||||
|
||||
@app.template_filter('readable_delta')
|
||||
def readable_delta(from_seconds, until_seconds=None):
|
||||
# Returns a nice readable delta.
|
||||
def plur(it):
|
||||
try:
|
||||
size = len(it)
|
||||
except TypeError:
|
||||
size = int(it)
|
||||
return '' if size == 1 else 's'
|
||||
|
||||
if not until_seconds:
|
||||
until_seconds = time.time()
|
||||
|
||||
seconds = int(until_seconds) - int(from_seconds)
|
||||
delta = datetime.timedelta(seconds=seconds)
|
||||
delta_minutes = delta.seconds // 60
|
||||
delta_hours = delta_minutes // 60
|
||||
|
||||
if delta.days:
|
||||
return '%d day%s, %d hour%s' % (
|
||||
delta.days,
|
||||
plur(delta.days),
|
||||
(delta_hours),
|
||||
plur(delta_hours))
|
||||
elif delta_hours:
|
||||
return '%d hour%s, %d minute%s' % (
|
||||
delta_hours,
|
||||
plur(delta_hours),
|
||||
(delta_minutes - delta_hours * 60),
|
||||
plur(delta_minutes))
|
||||
elif delta_minutes:
|
||||
return '%d minute%s' % (delta_minutes, plur(delta_minutes))
|
||||
else:
|
||||
return '%d second%s' % (delta.seconds, plur(delta.seconds))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
@@ -1,31 +1,30 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
{% block head %}
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<!-- Bootstrap CSS -->
|
||||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"
|
||||
integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO"
|
||||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO"
|
||||
crossorigin="anonymous">
|
||||
|
||||
<link rel="stylesheet" type="text/css" href="../static/css/style.css">
|
||||
<title>libOpenAnal appliance</title>
|
||||
{% endblock %}
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="container" id="content">{% block content %}
|
||||
<h1>Hexor's conf_bot data extractor tool</h1>{% endblock %}</div>
|
||||
{% block scripts %}
|
||||
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"
|
||||
integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"
|
||||
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"
|
||||
crossorigin="anonymous"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"
|
||||
integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49"
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49"
|
||||
crossorigin="anonymous"></script>
|
||||
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"
|
||||
integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy"
|
||||
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy"
|
||||
crossorigin="anonymous"></script>
|
||||
{% endblock %}
|
||||
</body>
|
||||
|
||||
</html>
|
@@ -19,10 +19,9 @@
|
||||
</li>
|
||||
</ul>
|
||||
<br>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-12">
|
||||
<h4>Totals</h4>
|
||||
<h4>Summary</h4>
|
||||
<b>Users: </b> {{ totals.users[0] }}<br>
|
||||
<b>Unique words: </b> {{ totals.words[0] }}<br>
|
||||
<b>Words said: </b> {{ totals.relations[0] }}<br>
|
||||
|
@@ -21,7 +21,7 @@
|
||||
<br>
|
||||
<div class="row">
|
||||
<div class="col-sm-12">
|
||||
<h4>Totals</h4>
|
||||
<h4>Summary</h4>
|
||||
<b>Users: </b> {{ totals.users[0] }}<br>
|
||||
<b>Unique words: </b> {{ totals.words[0] }}<br>
|
||||
<b>Words said: </b> {{ totals.relations[0] }}<br>
|
||||
@@ -33,25 +33,19 @@
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">#</th>
|
||||
<th scope="col"><a
|
||||
href="./?order=first_name&sorting={%- if sorting == 'ASC' -%}DESC{%- else -%}ASC{%- endif -%}">First
|
||||
<th scope="col"><a href="./?order=first_name&sorting={%- if sorting == 'ASC' -%}DESC{%- else -%}ASC{%- endif -%}">First
|
||||
name</a></th>
|
||||
<th scope="col"><a
|
||||
href="./?order=last_name&sorting={%- if sorting == 'ASC' -%}DESC{%- else -%}ASC{%- endif -%}">Last
|
||||
<th scope="col"><a href="./?order=last_name&sorting={%- if sorting == 'ASC' -%}DESC{%- else -%}ASC{%- endif -%}">Last
|
||||
name</a></th>
|
||||
<th scope="col"><a
|
||||
href="./?order=username&sorting={%- if sorting == 'ASC' -%}DESC{%- else -%}ASC{%- endif -%}">Username</a>
|
||||
<th scope="col"><a href="./?order=username&sorting={%- if sorting == 'ASC' -%}DESC{%- else -%}ASC{%- endif -%}">Username</a>
|
||||
</th>
|
||||
<th scope="col"><a href="./?order=id&sorting={%- if sorting == 'ASC' -%}DESC{%- else -%}ASC{%- endif -%}">User
|
||||
ID</a></th>
|
||||
<th scope="col"><a
|
||||
href="./?order=firstly_seen&sorting={%- if sorting == 'ASC' -%}DESC{%- else -%}ASC{%- endif -%}">Firstly
|
||||
<th scope="col"><a href="./?order=firstly_seen&sorting={%- if sorting == 'ASC' -%}DESC{%- else -%}ASC{%- endif -%}">Firstly
|
||||
seen</a></th>
|
||||
<th scope="col"><a
|
||||
href="./?order=last_activity&sorting={%- if sorting == 'ASC' -%}DESC{%- else -%}ASC{%- endif -%}">Last
|
||||
<th scope="col"><a href="./?order=last_activity&sorting={%- if sorting == 'ASC' -%}DESC{%- else -%}ASC{%- endif -%}">Last
|
||||
activity</a></th>
|
||||
<th scope="col"><a
|
||||
href="./?order=count&sorting={%- if sorting == 'ASC' -%}DESC{%- else -%}ASC{%- endif -%}">Word
|
||||
<th scope="col"><a href="./?order=count&sorting={%- if sorting == 'ASC' -%}DESC{%- else -%}ASC{%- endif -%}">Word
|
||||
count</a></th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
@@ -19,21 +19,29 @@
|
||||
</li>
|
||||
</ul>
|
||||
<br>
|
||||
<form action="/" method="get">
|
||||
<div class="row">
|
||||
<div class="col-sm-12">
|
||||
<h4>Summary</h4>
|
||||
<b>Board: </b> {{ board }}<br>
|
||||
<b>Threads: </b> {{ threads|length }}<br>
|
||||
<b>Total posts: </b> {{ posts }}<br>
|
||||
</div>
|
||||
</div>
|
||||
<hr>
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-md-4"></div>
|
||||
<div class="col-md-4 offset-md-4">
|
||||
<form action="/stat" method="get">
|
||||
<div class="input-group mb-3">
|
||||
<input type="text" class="form-control" placeholder="Board" aria-label="Board"
|
||||
aria-describedby="button-stat" name="board">
|
||||
<input type="text" class="form-control" placeholder="Board" aria-label="Board" aria-describedby="button-stat"
|
||||
name="board">
|
||||
<div class="input-group-append">
|
||||
<button class="btn btn-primary" type="submit" id="button-stat">Get stat</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<div class="row">
|
||||
<div class="col-sm-12">
|
||||
<h4>Info</h4>
|
||||
<b>Board: </b> {{ board }}<br>
|
||||
<b>Threads: </b> {{ threads|length }}<br>
|
||||
<b>Total posts: </b> {{ posts }}<br>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<br>
|
||||
@@ -42,20 +50,14 @@
|
||||
<tr>
|
||||
<th scope="col">#</th>
|
||||
<th scope="col">Subject</th>
|
||||
<th scope="col"><a
|
||||
href="./stat?board={{ board }}&order=posts&sorting={%- if sorting == 'ASC' -%}DESC{%- else -%}ASC{%- endif -%}">Posts</a>
|
||||
<th scope="col"><a href="./stat?board={{ board }}&order=posts&sorting={%- if sorting == 'ASC' -%}DESC{%- else -%}ASC{%- endif -%}">Posts</a>
|
||||
</th>
|
||||
<th scope="col"><a
|
||||
href="./stat?board={{ board }}&order=views&sorting={%- if sorting == 'ASC' -%}DESC{%- else -%}ASC{%- endif -%}">Views</a>
|
||||
<th scope="col"><a href="./stat?board={{ board }}&order=views&sorting={%- if sorting == 'ASC' -%}DESC{%- else -%}ASC{%- endif -%}">Views</a>
|
||||
</th>
|
||||
<th scope="col"><a
|
||||
href="./stat?board={{ board }}&order=score&sorting={%- if sorting == 'ASC' -%}DESC{%- else -%}ASC{%- endif -%}">Score</a>
|
||||
<th scope="col"><a href="./stat?board={{ board }}&order=score&sorting={%- if sorting == 'ASC' -%}DESC{%- else -%}ASC{%- endif -%}">Score</a>
|
||||
</th>
|
||||
<th scope="col"><a
|
||||
href="./stat?board={{ board }}&order=timestamp&sorting={%- if sorting == 'ASC' -%}DESC{%- else -%}ASC{%- endif -%}">Created</a>
|
||||
</th>
|
||||
<th scope="col"><a
|
||||
href="./stat?board={{ board }}&order=lasthit&sorting={%- if sorting == 'ASC' -%}DESC{%- else -%}ASC{%- endif -%}">Lasthit</a>
|
||||
<th scope="col"><a href="./stat?board={{ board }}&order=lasthit&sorting={%- if sorting == 'ASC' -%}DESC{%- else -%}ASC{%- endif -%}">Lasthit</a>
|
||||
<th scope="col"><a href="./stat?board={{ board }}&order=timestamp&sorting={%- if sorting == 'ASC' -%}DESC{%- else -%}ASC{%- endif -%}">Age</a>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
@@ -63,12 +65,15 @@
|
||||
{% for thread in threads %}
|
||||
<tr>
|
||||
<th scope="row">{{ loop.index }}</th>
|
||||
<td><a href="https://2ch.hk/b/res/{{ thread['num'] }}.html">{{ thread['subject'] }}</a></td>
|
||||
<td><a href="https://2ch.hk/{{board}}/res/{{ thread['num'] }}.html">{{ thread['subject'] }}</a></td>
|
||||
<td>{{ thread['posts_count'] }}</td>
|
||||
<td>{{ thread['views'] }}</td>
|
||||
<td>{{ "%.2f"|format(thread['score']|float) }}</td>
|
||||
<td>{{ thread['timestamp'] | time }}</td>
|
||||
<td>{{ thread['lasthit'] | time }}</td>
|
||||
<td data-toggle="tooltip" data-placement="right" title="Last hit: {{ thread['lasthit']|time }}">{{thread['lasthit']|readable_delta(now)}}
|
||||
ago
|
||||
</td>
|
||||
<td data-toggle="tooltip" data-placement="right" title="Created: {{ thread['timestamp']|time }}">{{thread['timestamp']|readable_delta(thread['lasthit'])}}</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
|
@@ -73,8 +73,8 @@
|
||||
<td>{{ word[0] }}</td>
|
||||
{% if not loop.last %}
|
||||
{% if (word[1]/loop.nextitem[1]) > 2 %}
|
||||
<td><span class="badge badge-danger" data-toggle="tooltip" data-placement="right"
|
||||
title="Must have been abused">{{ word[1] }} </span></td>
|
||||
<td><span class="badge badge-danger" data-toggle="tooltip" data-placement="right" title="Must have been abused">{{
|
||||
word[1] }} </span></td>
|
||||
{% else %}
|
||||
<td><span class="badge badge-secondary">{{ word[1] }} </span></td>
|
||||
{% endif %}
|
||||
|
Reference in New Issue
Block a user