chg: Move the querying module, add very simple web interface
parent
4b7f0b8d95
commit
5ac57a9e1a
|
@ -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'])
|
||||
|
||||
|
||||
|
|
|
@ -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,0 +1,9 @@
|
|||
# Usage
|
||||
|
||||
Install the dependencies, run
|
||||
|
||||
```bash
|
||||
export FLASK_APP=${BGPRANKING_HOME}/website/web/__init__.py
|
||||
flask run --port 5005
|
||||
```
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
# Web thing
|
||||
flask
|
||||
flask-bootstrap
|
|
@ -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)
|
|
@ -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 %}
|
|
@ -0,0 +1,13 @@
|
|||
{% extends "bootstrap/base.html" %}
|
||||
|
||||
{% block scripts %}
|
||||
{{ super() }}
|
||||
{% endblock %}
|
||||
|
||||
{% block head %}
|
||||
{{ super() }}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
{{ super() }}
|
||||
{% endblock %}
|
Loading…
Reference in New Issue