chg: Move the querying module, add very simple web interface

pull/12/head
Raphaël Vinot 2018-04-11 14:55:20 +02:00
parent 4b7f0b8d95
commit 5ac57a9e1a
8 changed files with 75 additions and 4 deletions

View File

@ -40,7 +40,10 @@ def get_list_storage_path():
def get_homedir():
if not os.environ.get('BGPRANKING_HOME'):
raise MissingEnv("BGPRANKING_HOME is missing. Run the following from the home directory of the repository: export BGPRANKING_HOME='./'")
guessed_home = Path(__file__).resolve().parent.parent.parent
raise MissingEnv(f"BGPRANKING_HOME is missing. \
Run the following command (assuming you run the code from the clonned repository):\
export BGPRANKING_HOME='{guessed_home}'")
return Path(os.environ['BGPRANKING_HOME'])

View File

@ -9,8 +9,8 @@ from dateutil.parser import parse
import logging
from redis import StrictRedis
from bgpranking.libs.helpers import get_socket_path
from bgpranking.libs.exceptions import InvalidDateFormat
from .libs.helpers import get_socket_path
from .libs.exceptions import InvalidDateFormat
Dates = TypeVar('Dates', datetime.datetime, datetime.date, str)
@ -20,7 +20,7 @@ class IPVersion(Enum):
v6 = 'v6'
class BGPRanking():
class Querying():
def __init__(self, loglevel: int=logging.DEBUG):
self.__init_logger(loglevel)

0
website/__init__.py Normal file
View File

9
website/readme.md Normal file
View File

@ -0,0 +1,9 @@
# Usage
Install the dependencies, run
```bash
export FLASK_APP=${BGPRANKING_HOME}/website/web/__init__.py
flask run --port 5005
```

3
website/requirements.txt Normal file
View File

@ -0,0 +1,3 @@
# Web thing
flask
flask-bootstrap

22
website/web/__init__.py Normal file
View File

@ -0,0 +1,22 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from flask import Flask, render_template
from flask_bootstrap import Bootstrap
from bgpranking.querying import Querying
app = Flask(__name__)
Bootstrap(app)
app.config['BOOTSTRAP_SERVE_LOCAL'] = True
app.debug = True
@app.route('/', methods=['GET'])
def index():
q = Querying()
ranks = q.asns_global_ranking(limit=-1)
return render_template('index.html', ranks=ranks)

View File

@ -0,0 +1,21 @@
{% extends "main.html" %}
{% block title %}BGP Ranking{% endblock %}
{% block content %}
<center>
<h1>BGP Ranking</h1></br></br>
</center>
<table class="table">
<tr>
<th>ASN</th>
<th>Rank</th>
</tr>
{% for asn, rank in ranks %}
<tr>
<td>{{asn}}</td>
<td>{{rank}}</td>
</tr>
{% endfor %}
</table>
{% endblock %}

View File

@ -0,0 +1,13 @@
{% extends "bootstrap/base.html" %}
{% block scripts %}
{{ super() }}
{% endblock %}
{% block head %}
{{ super() }}
{% endblock %}
{% block content %}
{{ super() }}
{% endblock %}