-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Jakub Kicinski <[email protected]>
- Loading branch information
Showing
2 changed files
with
63 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#!/usr/bin/env python3 | ||
# SPDX-License-Identifier: GPL-2.0 | ||
|
||
|
||
from flask import Flask | ||
from flask import request | ||
import couchdb | ||
import os | ||
|
||
|
||
app = Flask("NIPA contest query") | ||
|
||
user = os.getenv('DB_USER') | ||
pwd = os.getenv('DB_PWD') | ||
couch = couchdb.Server(f'http://{user}:{pwd}@127.0.0.1:5984') | ||
|
||
|
||
@app.route('/') | ||
def hello(): | ||
return '<h1>boo!</h1>' | ||
|
||
|
||
@app.route('/results') | ||
def results(): | ||
global couch | ||
|
||
br_cnt = request.args.get('branches') | ||
if not br_cnt: | ||
return {} | ||
|
||
return_rows = [] | ||
seen_br = set() | ||
offset = 0 | ||
done = False | ||
while not done: | ||
rows = couch["results"].find({ | ||
"selector": {}, | ||
"sort": [ | ||
{ | ||
"branch": "desc" | ||
} | ||
], | ||
"skip": offset, | ||
"limit": 100 | ||
}) | ||
offset += 100 | ||
|
||
done |= not list(rows) | ||
|
||
for row in rows: | ||
if row['branch'] not in seen_br: | ||
if len(seen_br) == br_cnt: | ||
done = True | ||
break | ||
seen_br.add(row['branch']) | ||
return_rows.append(row) | ||
|
||
return return_rows | ||
|
||
|
||
if __name__ == "__main__": | ||
app.run(host='0.0.0.0') |
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