diff --git a/var/www/Flask_server.py b/var/www/Flask_server.py index 2ee00295..c94b5285 100755 --- a/var/www/Flask_server.py +++ b/var/www/Flask_server.py @@ -9,10 +9,12 @@ import time import calendar from flask import Flask, render_template, jsonify, request import flask +import importlib import os +from os.path import join import sys sys.path.append(os.path.join(os.environ['AIL_BIN'], 'packages/')) -sys.path.append('./Flasks/') +sys.path.append('./modules/') import Paste from Date import Date @@ -25,15 +27,19 @@ cfg = Flask_config.cfg Flask_config.app = Flask(__name__, static_url_path='/static/') app = Flask_config.app -# import routes and functions from modules -import Flask_dashboard -import Flask_trendingcharts -import Flask_trendingmodules -import Flask_browsepastes -import Flask_sentiment -import Flask_terms -import Flask_search -import Flask_showpaste +# dynamically import routes and functions from modules +for root, dirs, files in os.walk('modules/'): + for directory in dirs: + #if directory == 'templates': + # continue + sys.path.append(join(root, directory)) + for name in files: + if name.startswith('Flask_') and name.endswith('.py'): + if name == 'Flask_config.py': + continue + name = name.strip('.py') + print('importing {}'.format(name)) + importlib.import_module(name) def list_len(s): return len(s) diff --git a/var/www/Flasks/Flask_browsepastes.py b/var/www/Flasks/Flask_browsepastes.py deleted file mode 100644 index b393ab9e..00000000 --- a/var/www/Flasks/Flask_browsepastes.py +++ /dev/null @@ -1,100 +0,0 @@ -#!/usr/bin/env python2 -# -*-coding:UTF-8 -* - -''' - Flask functions and routes for the trending modules page -''' -import redis -import json -import flask -from flask import Flask, render_template, jsonify, request - -import Paste - -# ============ VARIABLES ============ -import Flask_config - -app = Flask_config.app -cfg = Flask_config.cfg -max_preview_char = Flask_config.max_preview_char -max_preview_modal = Flask_config.max_preview_modal -r_serv_db = Flask_config.r_serv_db -# ============ FUNCTIONS ============ - -def getPastebyType(server, module_name): - all_path = [] - for path in server.smembers('WARNING_'+module_name): - all_path.append(path) - return all_path - - -def event_stream_getImportantPasteByModule(module_name): - index = 0 - all_pastes_list = getPastebyType(r_serv_db, module_name) - for path in all_pastes_list: - index += 1 - paste = Paste.Paste(path) - content = paste.get_p_content().decode('utf8', 'ignore') - content_range = max_preview_char if len(content)>max_preview_char else len(content)-1 - curr_date = str(paste._get_p_date()) - curr_date = curr_date[0:4]+'/'+curr_date[4:6]+'/'+curr_date[6:] - data = {} - data["module"] = module_name - data["index"] = index - data["path"] = path - data["content"] = content[0:content_range] - data["linenum"] = paste.get_lines_info()[0] - data["date"] = curr_date - data["char_to_display"] = max_preview_modal - data["finished"] = True if index == len(all_pastes_list) else False - yield 'retry: 100000\ndata: %s\n\n' % json.dumps(data) #retry to avoid reconnection of the browser - -# ============ ROUTES ============ - -@app.route("/browseImportantPaste/", methods=['GET']) -def browseImportantPaste(): - module_name = request.args.get('moduleName') - return render_template("browse_important_paste.html") - - -@app.route("/importantPasteByModule/", methods=['GET']) -def importantPasteByModule(): - module_name = request.args.get('moduleName') - - all_content = [] - paste_date = [] - paste_linenum = [] - all_path = [] - allPastes = getPastebyType(r_serv_db, module_name) - - for path in allPastes[0:10]: - all_path.append(path) - paste = Paste.Paste(path) - content = paste.get_p_content().decode('utf8', 'ignore') - content_range = max_preview_char if len(content)>max_preview_char else len(content)-1 - all_content.append(content[0:content_range].replace("\"", "\'").replace("\r", " ").replace("\n", " ")) - curr_date = str(paste._get_p_date()) - curr_date = curr_date[0:4]+'/'+curr_date[4:6]+'/'+curr_date[6:] - paste_date.append(curr_date) - paste_linenum.append(paste.get_lines_info()[0]) - - if len(allPastes) > 10: - finished = False - else: - finished = True - - return render_template("important_paste_by_module.html", - moduleName=module_name, - all_path=all_path, - content=all_content, - paste_date=paste_date, - paste_linenum=paste_linenum, - char_to_display=max_preview_modal, - finished=finished) - -@app.route("/_getImportantPasteByModule") -def getImportantPasteByModule(): - module_name = request.args.get('moduleName') - return flask.Response(event_stream_getImportantPasteByModule(module_name), mimetype="text/event-stream") - - diff --git a/var/www/Flasks/Flask_corpus.py b/var/www/Flasks/Flask_corpus.py deleted file mode 100644 index 7805e66e..00000000 --- a/var/www/Flasks/Flask_corpus.py +++ /dev/null @@ -1,219 +0,0 @@ -#!/usr/bin/env python2 -# -*-coding:UTF-8 -* - -''' - Flask functions and routes for the trending modules page -''' -import redis -import datetime -import calendar -import flask -from flask import Flask, render_template, jsonify, request - -import Paste - -# ============ VARIABLES ============ -import Flask_config - -app = Flask_config.app -cfg = Flask_config.cfg -r_serv_corpus = Flask_config.r_serv_corpus -# ============ FUNCTIONS ============ - -def Corpus_getValueOverRange(word, startDate, num_day): - passed_days = 0 - oneDay = 60*60*24 - to_return = [] - curr_to_return = 0 - for timestamp in range(startDate, startDate - max(num_day)*oneDay, -oneDay): - value = r_serv_corpus.hget(timestamp, word) - curr_to_return += int(value) if value is not None else 0 - for i in num_day: - if passed_days == i-1: - to_return.append(curr_to_return) - passed_days += 1 - return to_return - - -# ============ ROUTES ============ - -@app.route("/corpus_management/") -def corpus_management(): - TrackedCorpusSet_Name = "TrackedSetCorpusSet" - TrackedCorpusDate_Name = "TrackedCorpusDate" - - today = datetime.datetime.now() - today = today.replace(hour=0, minute=0, second=0, microsecond=0) - today_timestamp = calendar.timegm(today.timetuple()) - - track_list = [] - track_list_values = [] - track_list_num_of_paste = [] - for tracked_corpus in r_serv_corpus.smembers(TrackedCorpusSet_Name): - track_list.append(tracked_corpus) - value_range = Corpus_getValueOverRange(tracked_corpus, today_timestamp, [1, 7, 31]) - - corpus_date = r_serv_corpus.hget(TrackedCorpusDate_Name, tracked_corpus) - - set_paste_name = "tracked_" + tracked_corpus - track_list_num_of_paste.append(r_serv_corpus.scard(set_paste_name)) - corpus_date = datetime.datetime.utcfromtimestamp(int(corpus_date)) if corpus_date is not None else "No date recorded" - value_range.append(corpus_date) - track_list_values.append(value_range) - - - return render_template("corpus_management.html", black_list=black_list, track_list=track_list, track_list_values=track_list_values, track_list_num_of_paste=track_list_num_of_paste) - - -@app.route("/corpus_management_query_paste/") -def corpus_management_query_paste(): - corpus = request.args.get('corpus') - TrackedCorpusSet_Name = "TrackedSetCorpusSet" - paste_info = [] - - set_paste_name = "tracked_" + corpus - track_list_path = r_serv_corpus.smembers(set_paste_name) - - for path in track_list_path: - paste = Paste.Paste(path) - p_date = str(paste._get_p_date()) - p_date = p_date[6:]+'/'+p_date[4:6]+'/'+p_date[0:4] - p_source = paste.p_source - p_encoding = paste._get_p_encoding() - p_size = paste.p_size - p_mime = paste.p_mime - p_lineinfo = paste.get_lines_info() - p_content = paste.get_p_content().decode('utf-8', 'ignore') - if p_content != 0: - p_content = p_content[0:400] - paste_info.append({"path": path, "date": p_date, "source": p_source, "encoding": p_encoding, "size": p_size, "mime": p_mime, "lineinfo": p_lineinfo, "content": p_content}) - - return jsonify(paste_info) - - -@app.route("/corpus_management_query/") -def corpus_management_query(): - TrackedCorpusDate_Name = "TrackedCorpusDate" - corpus = request.args.get('corpus') - - today = datetime.datetime.now() - today = today.replace(hour=0, minute=0, second=0, microsecond=0) - today_timestamp = calendar.timegm(today.timetuple()) - value_range = corpus_getValueOverRange(corpus, today_timestamp, [1, 7, 31]) - - corpus_date = r_serv_corpus.hget(TrackedCorpusDate_Name, corpus) - - corpus_date = datetime.datetime.utcfromtimestamp(int(corpus_date)) if corpus_date is not None else "No date recorded" - value_range.append(str(corpus_date)) - return jsonify(value_range) - - -@app.route("/corpus_management_action/", methods=['GET']) -def corpus_management_action(): - TrackedCorpusSet_Name = "TrackedSetCorpusSet" - TrackedCorpusDate_Name = "TrackedCorpusDate" - - today = datetime.datetime.now() - today = today.replace(microsecond=0) - today_timestamp = calendar.timegm(today.timetuple()) - - - section = request.args.get('section') - action = request.args.get('action') - corpus = request.args.get('corpus') - if action is None or corpus is None: - return "None" - else: - if section == "followCorpus": - if action == "add": - r_serv_corpus.sadd(TrackedCorpusSet_Name, corpus.lower()) - r_serv_corpus.hset(TrackedCorpusDate_Name, corpus, today_timestamp) - else: - r_serv_corpus.srem(TrackedCorpusSet_Name, corpus.lower()) - else: - return "None" - - to_return = {} - to_return["section"] = section - to_return["action"] = action - to_return["corpus"] = corpus - return jsonify(to_return) - - - -@app.route("/corpus_plot_tool/") -def corpus_plot_tool(): - corpus = request.args.get('corpus') - if corpus is not None: - return render_template("corpus_plot_tool.html", corpus=corpus) - else: - return render_template("corpus_plot_tool.html", corpus="") - - -@app.route("/corpus_plot_tool_data/") -def corpus_plot_tool_data(): - oneDay = 60*60*24 - range_start = datetime.datetime.utcfromtimestamp(int(float(request.args.get('range_start')))) if request.args.get('range_start') is not None else 0; - range_start = range_start.replace(hour=0, minute=0, second=0, microsecond=0) - range_start = calendar.timegm(range_start.timetuple()) - range_end = datetime.datetime.utcfromtimestamp(int(float(request.args.get('range_end')))) if request.args.get('range_end') is not None else 0; - range_end = range_end.replace(hour=0, minute=0, second=0, microsecond=0) - range_end = calendar.timegm(range_end.timetuple()) - corpus = request.args.get('corpus') - - if corpus is None: - return "None" - else: - value_range = [] - for timestamp in range(range_start, range_end+oneDay, oneDay): - value = r_serv_corpus.hget(timestamp, corpus) - curr_value_range = int(value) if value is not None else 0 - value_range.append([timestamp, curr_value_range]) - value_range.insert(0,corpus) - return jsonify(value_range) - - -@app.route("/corpus_plot_top/") -def corpus_plot_top(): - return render_template("corpus_plot_top.html") - - -@app.route("/corpus_plot_top_data/") -def corpus_plot_top_data(): - oneDay = 60*60*24 - today = datetime.datetime.now() - today = today.replace(hour=0, minute=0, second=0, microsecond=0) - today_timestamp = calendar.timegm(today.timetuple()) - - set_day = "TopCorpusFreq_set_day_" + str(today_timestamp) - set_week = "TopCorpusFreq_set_week"; - set_month = "TopCorpusFreq_set_month"; - - the_set = request.args.get('set') - num_day = int(request.args.get('num_day')) - if the_set is None: - return "None" - else: - to_return = [] - if the_set == "TopCorpusFreq_set_day": - the_set += "_" + str(today_timestamp) - - for corpus, tot_value in r_serv_corpus.zrevrangebyscore(the_set, '+inf', '-inf', withscores=True, start=0, num=20): - position = {} - position['day'] = r_serv_corpus.zrevrank(set_day, corpus) - position['day'] = position['day']+1 if position['day'] is not None else "<20" - position['week'] = r_serv_corpus.zrevrank(set_week, corpus) - position['week'] = position['week']+1 if position['week'] is not None else "<20" - position['month'] = r_serv_corpus.zrevrank(set_month, corpus) - position['month'] = position['month']+1 if position['month'] is not None else "<20" - value_range = [] - for timestamp in range(today_timestamp, today_timestamp - num_day*oneDay, -oneDay): - value = r_serv_corpus.hget(timestamp, corpus) - curr_value_range = int(value) if value is not None else 0 - value_range.append([timestamp, curr_value_range]) - - to_return.append([corpus, value_range, tot_value, position]) - - return jsonify(to_return) - - diff --git a/var/www/Flasks/Flask_config.py b/var/www/modules/Flask_config.py similarity index 100% rename from var/www/Flasks/Flask_config.py rename to var/www/modules/Flask_config.py diff --git a/var/www/templates/browse_important_paste.html b/var/www/modules/browsepastes/templates/browse_important_paste.html similarity index 94% rename from var/www/templates/browse_important_paste.html rename to var/www/modules/browsepastes/templates/browse_important_paste.html index 61015a15..09a21a70 100644 --- a/var/www/templates/browse_important_paste.html +++ b/var/www/modules/browsepastes/templates/browse_important_paste.html @@ -49,7 +49,7 @@ - + @@ -130,7 +130,7 @@ $("#"+activePage).addClass("active"); var dataPath = 'credential'; - $.get("{{ url_for('importantPasteByModule') }}"+"?moduleName="+dataPath, function(data, status){ + $.get("{{ url_for('browsepastes.importantPasteByModule') }}"+"?moduleName="+dataPath, function(data, status){ $('#'+dataPath+'-tab').html(data); }); }); @@ -144,7 +144,7 @@ var loading_gif = " {{ i + 1 }} - {{ path }} + {{ path }} {{ paste_date[i] }} {{ paste_linenum[i] }} -

+

{% set i = i + 1 %} {% endfor %} @@ -47,7 +47,7 @@ function deploy_source() { if(typeof(EventSource) !== "undefined" && typeof(source) !== "") { $("#load_more_json_button1").show(); $("#load_more_json_button2").show(); - var source = new EventSource("{{ url_for('getImportantPasteByModule') }}"+"?moduleName="+moduleName); + var source = new EventSource("{{ url_for('browsepastes.getImportantPasteByModule') }}"+"?moduleName="+moduleName); source.onmessage = function(event) { var feed = jQuery.parseJSON( event.data ); curr_numElem = parseInt($("#myTable_"+moduleName).attr('data-numElem')); @@ -93,10 +93,10 @@ function add_entries_X(to_add) { elem_added++; search_table.row.add( [ feed.index, - " "+ feed.path +"", + " "+ feed.path +"", feed.date, feed.linenum, - "

" + "

" ] ).draw( false ); $("#myTable_"+moduleName).attr('data-numElem', curr_numElem+1); } @@ -195,7 +195,7 @@ $(document).ready(function(){ $("[data-toggle='modal']").off('click.openmodal').on("click.openmodal", function (event) { event.preventDefault(); var modal=$(this); - var url = " {{ url_for('showpreviewpaste') }}?paste=" + $(this).attr('data-path') + "&num=" + $(this).attr('data-num'); + var url = " {{ url_for('showsavedpastes.showpreviewpaste') }}?paste=" + $(this).attr('data-path') + "&num=" + $(this).attr('data-num'); last_clicked_paste = $(this).attr('data-num'); $.get(url, function (data) { @@ -221,7 +221,7 @@ $(document).ready(function(){ // On click, donwload all paste's content $("#load-more-button").on("click", function (event) { if (complete_paste == null) { //Donwload only once - $.get("{{ url_for('getmoredata') }}"+"?paste="+$(modal).attr('data-path'), function(data, status){ + $.get("{{ url_for('showsavedpastes.getmoredata') }}"+"?paste="+$(modal).attr('data-path'), function(data, status){ complete_paste = data; update_preview(); }); diff --git a/var/www/Flasks/Flask_dashboard.py b/var/www/modules/dashboard/Flask_dashboard.py similarity index 86% rename from var/www/Flasks/Flask_dashboard.py rename to var/www/modules/dashboard/Flask_dashboard.py index 79307f9c..7560664e 100644 --- a/var/www/Flasks/Flask_dashboard.py +++ b/var/www/modules/dashboard/Flask_dashboard.py @@ -8,7 +8,7 @@ import json import datetime import flask -from flask import Flask, render_template, jsonify, request +from flask import Flask, render_template, jsonify, request, Blueprint # ============ VARIABLES ============ import Flask_config @@ -17,6 +17,9 @@ app = Flask_config.app cfg = Flask_config.cfg r_serv = Flask_config.r_serv r_serv_log = Flask_config.r_serv_log + +dashboard = Blueprint('dashboard', __name__, template_folder='templates') + # ============ FUNCTIONS ============ def event_stream(): @@ -51,18 +54,21 @@ def get_queues(r): # ============ ROUTES ============ -@app.route("/_logs") +@dashboard.route("/_logs") def logs(): return flask.Response(event_stream(), mimetype="text/event-stream") -@app.route("/_stuff", methods=['GET']) +@dashboard.route("/_stuff", methods=['GET']) def stuff(): return jsonify(row1=get_queues(r_serv)) -@app.route("/") +@dashboard.route("/") def index(): default_minute = cfg.get("Flask", "minute_processed_paste") threshold_stucked_module = cfg.getint("Module_ModuleInformation", "threshold_stucked_module") return render_template("index.html", default_minute = default_minute, threshold_stucked_module=threshold_stucked_module) + +# ========= REGISTRATION ========= +app.register_blueprint(dashboard) diff --git a/var/www/templates/Queue_live_Monitoring.html b/var/www/modules/dashboard/templates/Queue_live_Monitoring.html similarity index 100% rename from var/www/templates/Queue_live_Monitoring.html rename to var/www/modules/dashboard/templates/Queue_live_Monitoring.html diff --git a/var/www/templates/index.html b/var/www/modules/dashboard/templates/index.html similarity index 96% rename from var/www/templates/index.html rename to var/www/modules/dashboard/templates/index.html index 48f81a7d..bb80b84e 100644 --- a/var/www/templates/index.html +++ b/var/www/modules/dashboard/templates/index.html @@ -43,7 +43,7 @@
- + @@ -176,7 +176,7 @@ - + @@ -357,7 +357,7 @@ var plot_month; var promises = []; // Used to know when everything has been received -promises.push($.getJSON("{{ url_for('terms_plot_top_data') }}", { set: set_today, num_day: 5, per_paste: per_paste }, function(data, status){ +promises.push($.getJSON("{{ url_for('terms.terms_plot_top_data') }}", { set: set_today, num_day: 5, per_paste: per_paste }, function(data, status){ data.sort(function(a, b){return b[2]-a[2];}); // Sort data var table_today = $("#table-today") @@ -398,7 +398,7 @@ promises.push($.getJSON("{{ url_for('terms_plot_top_data') }}", { set: set_today })); -promises.push($.getJSON("{{ url_for('terms_plot_top_data') }}", { set: set_week, num_day: 7, per_paste: per_paste }, function(data, status){ +promises.push($.getJSON("{{ url_for('terms.terms_plot_top_data') }}", { set: set_week, num_day: 7, per_paste: per_paste }, function(data, status){ data.sort(function(a, b){return b[2]-a[2];}); // Sort data var table = $("#table-week") @@ -438,7 +438,7 @@ promises.push($.getJSON("{{ url_for('terms_plot_top_data') }}", { set: set_week, }); })); -promises.push($.getJSON("{{ url_for('terms_plot_top_data') }}", { set: set_month, num_day: 31, per_paste: per_paste }, function(data, status){ +promises.push($.getJSON("{{ url_for('terms.terms_plot_top_data') }}", { set: set_month, num_day: 31, per_paste: per_paste }, function(data, status){ data.sort(function(a, b){return b[2]-a[2];}); // Sort data var table = $("#table-month") @@ -507,7 +507,7 @@ function perform_operation(){ var data_to_send = { section: curr_section, action:"add", term: curr_term}; - $.get("{{ url_for('terms_management_action') }}", data_to_send, function(data, status){ + $.get("{{ url_for('terms.terms_management_action') }}", data_to_send, function(data, status){ if(status == "success") { location.reload(); } diff --git a/var/www/Flasks/Flask_trendingcharts.py b/var/www/modules/trendingcharts/Flask_trendingcharts.py similarity index 84% rename from var/www/Flasks/Flask_trendingcharts.py rename to var/www/modules/trendingcharts/Flask_trendingcharts.py index fdb1a3d4..cb3f7baa 100644 --- a/var/www/Flasks/Flask_trendingcharts.py +++ b/var/www/modules/trendingcharts/Flask_trendingcharts.py @@ -8,7 +8,7 @@ import redis import datetime from Date import Date import flask -from flask import Flask, render_template, jsonify, request +from flask import Flask, render_template, jsonify, request, Blueprint # ============ VARIABLES ============ import Flask_config @@ -16,6 +16,9 @@ import Flask_config app = Flask_config.app cfg = Flask_config.cfg r_serv_charts = Flask_config.r_serv_charts + +trendings = Blueprint('trendings', __name__, template_folder='templates') + # ============ FUNCTIONS ============ def get_date_range(num_day): @@ -30,7 +33,7 @@ def get_date_range(num_day): # ============ ROUTES ============ -@app.route("/_progressionCharts", methods=['GET']) +@trendings.route("/_progressionCharts", methods=['GET']) def progressionCharts(): attribute_name = request.args.get('attributeName') trending_name = request.args.get('trendingName') @@ -53,21 +56,23 @@ def progressionCharts(): keyw_value = r_serv_charts.zrevrangebyscore(redis_progression_name, '+inf', '-inf', withscores=True, start=0, num=10) return jsonify(keyw_value) -@app.route("/wordstrending/") +@trendings.route("/wordstrending/") def wordstrending(): default_display = cfg.get("Flask", "default_display") return render_template("Wordstrending.html", default_display = default_display) -@app.route("/protocolstrending/") +@trendings.route("/protocolstrending/") def protocolstrending(): default_display = cfg.get("Flask", "default_display") return render_template("Protocolstrending.html", default_display = default_display) -@app.route("/trending/") +@trendings.route("/trending/") def trending(): default_display = cfg.get("Flask", "default_display") return render_template("Trending.html", default_display = default_display) +# ========= REGISTRATION ========= +app.register_blueprint(trendings) diff --git a/var/www/templates/Trending.html b/var/www/modules/trendingcharts/templates/Trending.html similarity index 98% rename from var/www/templates/Trending.html rename to var/www/modules/trendingcharts/templates/Trending.html index f4e49f3c..5cf914f9 100644 --- a/var/www/templates/Trending.html +++ b/var/www/modules/trendingcharts/templates/Trending.html @@ -44,7 +44,7 @@ - + diff --git a/var/www/templates/trending_graphs/Domainstrending.html b/var/www/modules/trendingcharts/templates/trending_graphs/Domainstrending.html similarity index 100% rename from var/www/templates/trending_graphs/Domainstrending.html rename to var/www/modules/trendingcharts/templates/trending_graphs/Domainstrending.html diff --git a/var/www/templates/trending_graphs/Moduletrending.html b/var/www/modules/trendingcharts/templates/trending_graphs/Moduletrending.html similarity index 100% rename from var/www/templates/trending_graphs/Moduletrending.html rename to var/www/modules/trendingcharts/templates/trending_graphs/Moduletrending.html diff --git a/var/www/templates/trending_graphs/Protocolstrending.html b/var/www/modules/trendingcharts/templates/trending_graphs/Protocolstrending.html similarity index 100% rename from var/www/templates/trending_graphs/Protocolstrending.html rename to var/www/modules/trendingcharts/templates/trending_graphs/Protocolstrending.html diff --git a/var/www/templates/trending_graphs/Tldstrending.html b/var/www/modules/trendingcharts/templates/trending_graphs/Tldstrending.html similarity index 100% rename from var/www/templates/trending_graphs/Tldstrending.html rename to var/www/modules/trendingcharts/templates/trending_graphs/Tldstrending.html diff --git a/var/www/templates/trending_graphs/Wordstrending.html b/var/www/modules/trendingcharts/templates/trending_graphs/Wordstrending.html similarity index 100% rename from var/www/templates/trending_graphs/Wordstrending.html rename to var/www/modules/trendingcharts/templates/trending_graphs/Wordstrending.html diff --git a/var/www/Flasks/Flask_trendingmodules.py b/var/www/modules/trendingmodules/Flask_trendingmodules.py similarity index 91% rename from var/www/Flasks/Flask_trendingmodules.py rename to var/www/modules/trendingmodules/Flask_trendingmodules.py index 19895df9..aee5eef2 100644 --- a/var/www/Flasks/Flask_trendingmodules.py +++ b/var/www/modules/trendingmodules/Flask_trendingmodules.py @@ -8,7 +8,7 @@ import redis import datetime from Date import Date import flask -from flask import Flask, render_template, jsonify, request +from flask import Flask, render_template, jsonify, request, Blueprint # ============ VARIABLES ============ import Flask_config @@ -16,6 +16,9 @@ import Flask_config app = Flask_config.app cfg = Flask_config.cfg r_serv_charts = Flask_config.r_serv_charts + +trendingmodules = Blueprint('trendingmodules', __name__, template_folder='templates') + # ============ FUNCTIONS ============ # Iterate over elements in the module provided and return the today data or the last data @@ -43,7 +46,7 @@ def get_date_range(num_day): # ============ ROUTES ============ -@app.route("/_moduleCharts", methods=['GET']) +@trendingmodules.route("/_moduleCharts", methods=['GET']) def modulesCharts(): keyword_name = request.args.get('keywordName') module_name = request.args.get('moduleName') @@ -69,7 +72,7 @@ def modulesCharts(): return jsonify(member_set) -@app.route("/_providersChart", methods=['GET']) +@trendingmodules.route("/_providersChart", methods=['GET']) def providersChart(): keyword_name = request.args.get('keywordName') module_name = request.args.get('moduleName') @@ -106,8 +109,10 @@ def providersChart(): return jsonify(member_set) -@app.route("/moduletrending/") +@trendingmodules.route("/moduletrending/") def moduletrending(): return render_template("Moduletrending.html") +# ========= REGISTRATION ========= +app.register_blueprint(trendingmodules) diff --git a/var/www/templates/Moduletrending.html b/var/www/modules/trendingmodules/templates/Moduletrending.html similarity index 96% rename from var/www/templates/Moduletrending.html rename to var/www/modules/trendingmodules/templates/Moduletrending.html index a2635868..28fc3aa2 100644 --- a/var/www/templates/Moduletrending.html +++ b/var/www/modules/trendingmodules/templates/Moduletrending.html @@ -36,7 +36,7 @@ - + diff --git a/var/www/templates/header.html b/var/www/templates/header.html index d2bfe0a6..ae394973 100644 --- a/var/www/templates/header.html +++ b/var/www/templates/header.html @@ -1,22 +1,22 @@