-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9290ff9
commit 0f88b59
Showing
3 changed files
with
38 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,12 @@ | |
from flask import Flask, request, jsonify | ||
|
||
app = Flask(__name__) | ||
app.config['JSONIFY_PRETTYPRINT_REGULAR'] = False | ||
app.config['JSON_AS_ASCII'] = False | ||
index = "path_to_index_folder" | ||
|
||
s = searcher.Searcher(index) | ||
|
||
|
||
@app.route('/') | ||
def home(): | ||
|
@@ -13,67 +17,74 @@ def home(): | |
|
||
@app.route('/views') | ||
def search_views(): | ||
s = searcher.Searcher(index) | ||
dmy = request.args.get('date', None) | ||
period = request.args.get('period', 'year') | ||
if dmy: | ||
dmy = dmy.split("-") | ||
seg = request.args.get('segment', None) | ||
seg, sid = which_segment(seg) | ||
return jsonify(s.search_views(dmy=dmy, period=period, site_id=sid, segment=seg)) | ||
res = dict() | ||
res["response"] = s.search_views(dmy=dmy, period=period, site_id=sid, segment=seg) | ||
return jsonify(res) | ||
|
||
|
||
@app.route('/visits') | ||
def search_visits(): | ||
s = searcher.Searcher(index) | ||
dmy = request.args.get('date', None) | ||
period = request.args.get('period', 'year') | ||
if dmy: | ||
dmy = dmy.split("-") | ||
seg = request.args.get('segment', None) | ||
seg, sid = which_segment(seg) | ||
return jsonify(s.search_visits(dmy=dmy, period=period, site_id=sid, segment=seg)) | ||
res = dict() | ||
res["response"] = s.search_visits(dmy=dmy, period=period, site_id=sid, segment=seg) | ||
return jsonify(res) | ||
|
||
|
||
@app.route('/country') | ||
def search_country(): | ||
s = searcher.Searcher(index) | ||
dmy = request.args.get('date', None) | ||
period = request.args.get('period', 'year') | ||
if dmy: | ||
dmy = dmy.split("-") | ||
seg = request.args.get('segment', None) | ||
seg, sid = which_segment(seg) | ||
return jsonify(s.search_country(dmy=dmy, period=period, site_id=sid, segment=seg)) | ||
res = dict() | ||
res["response"] = s.search_country(dmy=dmy, period=period, site_id=sid, segment=seg) | ||
return jsonify(res) | ||
|
||
|
||
@app.route('/urls') | ||
def search_urls(): | ||
s = searcher.Searcher(index) | ||
dmy = request.args.get('date', None) | ||
period = request.args.get('period', 'year') | ||
if dmy: | ||
dmy = dmy.split("-") | ||
seg = request.args.get('segment', None) | ||
seg, sid = which_segment(seg, route="urls") | ||
return jsonify(s.search_urls(dmy=dmy, period=period, site_id=sid, segment=seg)) | ||
res = dict() | ||
res["response"] = s.search_urls(dmy=dmy, period=period, site_id=sid, segment=seg) | ||
return jsonify(res) | ||
|
||
|
||
@app.route('/handle') | ||
def search_hanlde(): | ||
s = searcher.Searcher(index) | ||
dmy = request.args.get('date', None) | ||
period = request.args.get('period', 'year') | ||
segment = None | ||
if dmy: | ||
dmy = dmy.split("-") | ||
h = request.args.get('h') | ||
seg = request.args.get('segment', None) | ||
sid = [2, 4] | ||
if seg == "views": | ||
sid = 2 | ||
segment = "[email protected]/repository/xmlui/handle" | ||
elif seg == "downloads": | ||
sid = 4 | ||
return jsonify(s.search_handle(dmy=dmy, period=period, site_id=sid, handle=h)) | ||
res = dict() | ||
res["response"] = s.search_handle(dmy=dmy, period=period, site_id=sid, handle=h, segment=segment) | ||
return jsonify(res) | ||
|
||
|
||
def which_segment(seg, route=None): | ||
|