mirror of https://github.com/CIRCL/AIL-framework
Flask: Added support of LevelDB database depending of the year
parent
d632335760
commit
3b3f3aa89c
|
@ -11,7 +11,6 @@ from datetime import datetime
|
||||||
|
|
||||||
# FLASK #
|
# FLASK #
|
||||||
app = None
|
app = None
|
||||||
curYear = None #can be set to fit the needs, Correspond to the level-DB year to be used
|
|
||||||
|
|
||||||
# CONFIG #
|
# CONFIG #
|
||||||
configfile = os.path.join(os.environ['AIL_BIN'], 'packages/config.cfg')
|
configfile = os.path.join(os.environ['AIL_BIN'], 'packages/config.cfg')
|
||||||
|
@ -40,13 +39,6 @@ r_serv_charts = redis.StrictRedis(
|
||||||
port=cfg.getint("Redis_Level_DB_Trending", "port"),
|
port=cfg.getint("Redis_Level_DB_Trending", "port"),
|
||||||
db=cfg.getint("Redis_Level_DB_Trending", "db"))
|
db=cfg.getint("Redis_Level_DB_Trending", "db"))
|
||||||
|
|
||||||
# port generated automatically depending on the date
|
|
||||||
curYear = datetime.now().year if curYear is None else curYear
|
|
||||||
r_serv_db = redis.StrictRedis(
|
|
||||||
host=cfg.get("Redis_Level_DB", "host"),
|
|
||||||
port=curYear,
|
|
||||||
db=cfg.getint("Redis_Level_DB", "db"))
|
|
||||||
|
|
||||||
r_serv_sentiment = redis.StrictRedis(
|
r_serv_sentiment = redis.StrictRedis(
|
||||||
host=cfg.get("Redis_Level_DB_Sentiment", "host"),
|
host=cfg.get("Redis_Level_DB_Sentiment", "host"),
|
||||||
port=cfg.getint("Redis_Level_DB_Sentiment", "port"),
|
port=cfg.getint("Redis_Level_DB_Sentiment", "port"),
|
||||||
|
|
|
@ -7,6 +7,8 @@
|
||||||
import redis
|
import redis
|
||||||
import json
|
import json
|
||||||
import flask
|
import flask
|
||||||
|
import os
|
||||||
|
from datetime import datetime
|
||||||
from flask import Flask, render_template, jsonify, request, Blueprint
|
from flask import Flask, render_template, jsonify, request, Blueprint
|
||||||
|
|
||||||
import Paste
|
import Paste
|
||||||
|
@ -18,7 +20,25 @@ app = Flask_config.app
|
||||||
cfg = Flask_config.cfg
|
cfg = Flask_config.cfg
|
||||||
max_preview_char = Flask_config.max_preview_char
|
max_preview_char = Flask_config.max_preview_char
|
||||||
max_preview_modal = Flask_config.max_preview_modal
|
max_preview_modal = Flask_config.max_preview_modal
|
||||||
r_serv_db = Flask_config.r_serv_db
|
|
||||||
|
#init all lvlDB servers
|
||||||
|
curYear = datetime.now().year
|
||||||
|
r_serv_db = {}
|
||||||
|
# port generated automatically depending on available levelDB date
|
||||||
|
yearList = []
|
||||||
|
lvdbdir= os.path.join(os.environ['AIL_HOME'], "LEVEL_DB_DATA/")
|
||||||
|
for year in os.listdir(lvdbdir):
|
||||||
|
try:
|
||||||
|
intYear = int(year)
|
||||||
|
except:
|
||||||
|
continue
|
||||||
|
|
||||||
|
yearList.append([year, intYear, int(curYear) == intYear])
|
||||||
|
r_serv_db[intYear] = redis.StrictRedis(
|
||||||
|
host=cfg.get("Redis_Level_DB", "host"),
|
||||||
|
port=intYear,
|
||||||
|
db=cfg.getint("Redis_Level_DB", "db"))
|
||||||
|
yearList.sort(reverse=True)
|
||||||
|
|
||||||
browsepastes = Blueprint('browsepastes', __name__, template_folder='templates')
|
browsepastes = Blueprint('browsepastes', __name__, template_folder='templates')
|
||||||
|
|
||||||
|
@ -31,9 +51,9 @@ def getPastebyType(server, module_name):
|
||||||
return all_path
|
return all_path
|
||||||
|
|
||||||
|
|
||||||
def event_stream_getImportantPasteByModule(module_name):
|
def event_stream_getImportantPasteByModule(module_name, year):
|
||||||
index = 0
|
index = 0
|
||||||
all_pastes_list = getPastebyType(r_serv_db, module_name)
|
all_pastes_list = getPastebyType(r_serv_db[year], module_name)
|
||||||
for path in all_pastes_list:
|
for path in all_pastes_list:
|
||||||
index += 1
|
index += 1
|
||||||
paste = Paste.Paste(path)
|
paste = Paste.Paste(path)
|
||||||
|
@ -57,18 +77,19 @@ def event_stream_getImportantPasteByModule(module_name):
|
||||||
@browsepastes.route("/browseImportantPaste/", methods=['GET'])
|
@browsepastes.route("/browseImportantPaste/", methods=['GET'])
|
||||||
def browseImportantPaste():
|
def browseImportantPaste():
|
||||||
module_name = request.args.get('moduleName')
|
module_name = request.args.get('moduleName')
|
||||||
return render_template("browse_important_paste.html")
|
return render_template("browse_important_paste.html", year_list=yearList, selected_year=curYear)
|
||||||
|
|
||||||
|
|
||||||
@browsepastes.route("/importantPasteByModule/", methods=['GET'])
|
@browsepastes.route("/importantPasteByModule/", methods=['GET'])
|
||||||
def importantPasteByModule():
|
def importantPasteByModule():
|
||||||
module_name = request.args.get('moduleName')
|
module_name = request.args.get('moduleName')
|
||||||
|
currentSelectYear = int(request.args.get('year'))
|
||||||
|
|
||||||
all_content = []
|
all_content = []
|
||||||
paste_date = []
|
paste_date = []
|
||||||
paste_linenum = []
|
paste_linenum = []
|
||||||
all_path = []
|
all_path = []
|
||||||
allPastes = getPastebyType(r_serv_db, module_name)
|
allPastes = getPastebyType(r_serv_db[currentSelectYear], module_name)
|
||||||
|
|
||||||
for path in allPastes[0:10]:
|
for path in allPastes[0:10]:
|
||||||
all_path.append(path)
|
all_path.append(path)
|
||||||
|
@ -88,6 +109,7 @@ def importantPasteByModule():
|
||||||
|
|
||||||
return render_template("important_paste_by_module.html",
|
return render_template("important_paste_by_module.html",
|
||||||
moduleName=module_name,
|
moduleName=module_name,
|
||||||
|
year=currentSelectYear,
|
||||||
all_path=all_path,
|
all_path=all_path,
|
||||||
content=all_content,
|
content=all_content,
|
||||||
paste_date=paste_date,
|
paste_date=paste_date,
|
||||||
|
@ -95,10 +117,11 @@ def importantPasteByModule():
|
||||||
char_to_display=max_preview_modal,
|
char_to_display=max_preview_modal,
|
||||||
finished=finished)
|
finished=finished)
|
||||||
|
|
||||||
@browsepastes.route("/_getImportantPasteByModule")
|
@browsepastes.route("/_getImportantPasteByModule", methods=['GET'])
|
||||||
def getImportantPasteByModule():
|
def getImportantPasteByModule():
|
||||||
module_name = request.args.get('moduleName')
|
module_name = request.args.get('moduleName')
|
||||||
return flask.Response(event_stream_getImportantPasteByModule(module_name), mimetype="text/event-stream")
|
currentSelectYear = int(request.args.get('year'))
|
||||||
|
return flask.Response(event_stream_getImportantPasteByModule(module_name, currentSelectYear), mimetype="text/event-stream")
|
||||||
|
|
||||||
|
|
||||||
# ========= REGISTRATION =========
|
# ========= REGISTRATION =========
|
||||||
|
|
|
@ -63,6 +63,20 @@
|
||||||
</div>
|
</div>
|
||||||
<!-- /.col-lg-12 -->
|
<!-- /.col-lg-12 -->
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-12" style="margin-bottom: 0.2cm;">
|
||||||
|
<strong style="">Year: </strong>
|
||||||
|
<select class="form-control" id="index_year" style="display: inline-block; margin-bottom: 5px; width: 5%">
|
||||||
|
{% for yearElem in year_list %}
|
||||||
|
<option {% if yearElem[2] %} selected="selected" {% endif %} value="{{ yearElem[0] }}" >{{ yearElem[1] }}</option>
|
||||||
|
{% endfor %}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</br>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<!-- /.row -->
|
<!-- /.row -->
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
|
||||||
|
@ -117,9 +131,10 @@
|
||||||
$("#"+activePage).addClass("active");
|
$("#"+activePage).addClass("active");
|
||||||
|
|
||||||
var dataPath = 'credential';
|
var dataPath = 'credential';
|
||||||
$.get("{{ url_for('browsepastes.importantPasteByModule') }}"+"?moduleName="+dataPath, function(data, status){
|
$.get("{{ url_for('browsepastes.importantPasteByModule') }}"+"?moduleName="+dataPath+"&year="+currentSelectYear, function(data, status){
|
||||||
$('#'+dataPath+'-tab').html(data);
|
$('#'+dataPath+'-tab').html(data);
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -127,12 +142,23 @@
|
||||||
<script>
|
<script>
|
||||||
// When a pannel is shown, create the data-table.
|
// When a pannel is shown, create the data-table.
|
||||||
var previous_tab = $('[data-attribute-name="credential');
|
var previous_tab = $('[data-attribute-name="credential');
|
||||||
|
var currentTabName = previous_tab.attr('data-attribute-name');
|
||||||
var loading_gif = "<img id='loading-gif-modal' class='img-center' src=\"{{url_for('static', filename='image/loading.gif') }}\" height='26' width='26' style='margin: 4px;'>";
|
var loading_gif = "<img id='loading-gif-modal' class='img-center' src=\"{{url_for('static', filename='image/loading.gif') }}\" height='26' width='26' style='margin: 4px;'>";
|
||||||
|
var currentSelectYear = {{ selected_year }};
|
||||||
|
|
||||||
|
$('#index_year').on('change', function() {
|
||||||
|
currentSelectYear = this.value;
|
||||||
|
|
||||||
|
$.get("{{ url_for('browsepastes.importantPasteByModule') }}"+"?moduleName="+currentTabName+"&year="+currentSelectYear, function(data, status){
|
||||||
|
$('#'+currentTabName+'-tab').html(data);
|
||||||
|
});
|
||||||
|
})
|
||||||
|
|
||||||
$('.nav-tabs a').on('shown.bs.tab', function(event){
|
$('.nav-tabs a').on('shown.bs.tab', function(event){
|
||||||
var dataPath = $(event.target).attr('data-attribute-name');
|
var dataPath = $(event.target).attr('data-attribute-name');
|
||||||
$.get("{{ url_for('browsepastes.importantPasteByModule') }}"+"?moduleName="+dataPath, function(data, status){
|
currentTabName = dataPath;
|
||||||
var currentTab = $('[name].active').children();
|
$.get("{{ url_for('browsepastes.importantPasteByModule') }}"+"?moduleName="+currentTabName+"&year="+currentSelectYear, function(data, status){
|
||||||
|
currentTab = $('[name].active').children();
|
||||||
$('#'+previous_tab.attr('data-attribute-name')+'-tab').html(loading_gif);
|
$('#'+previous_tab.attr('data-attribute-name')+'-tab').html(loading_gif);
|
||||||
currentTab.removeClass( "active" );
|
currentTab.removeClass( "active" );
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@ function deploy_source() {
|
||||||
if(typeof(EventSource) !== "undefined" && typeof(source) !== "") {
|
if(typeof(EventSource) !== "undefined" && typeof(source) !== "") {
|
||||||
$("#load_more_json_button1").show();
|
$("#load_more_json_button1").show();
|
||||||
$("#load_more_json_button2").show();
|
$("#load_more_json_button2").show();
|
||||||
var source = new EventSource("{{ url_for('browsepastes.getImportantPasteByModule') }}"+"?moduleName="+moduleName);
|
var source = new EventSource("{{ url_for('browsepastes.getImportantPasteByModule') }}"+"?moduleName="+moduleName+"&year="+currentSelectYear);
|
||||||
source.onmessage = function(event) {
|
source.onmessage = function(event) {
|
||||||
var feed = jQuery.parseJSON( event.data );
|
var feed = jQuery.parseJSON( event.data );
|
||||||
curr_numElem = parseInt($("#myTable_"+moduleName).attr('data-numElem'));
|
curr_numElem = parseInt($("#myTable_"+moduleName).attr('data-numElem'));
|
||||||
|
@ -113,6 +113,7 @@ function add_entries_X(to_add) {
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
var moduleName = "{{ moduleName }}";
|
var moduleName = "{{ moduleName }}";
|
||||||
|
var currentSelectYear = "{{ year }}";
|
||||||
var search_table;
|
var search_table;
|
||||||
var last_clicked_paste;
|
var last_clicked_paste;
|
||||||
var can_change_modal_content = true;
|
var can_change_modal_content = true;
|
||||||
|
|
Loading…
Reference in New Issue