diff --git a/contest/backend/query.py b/contest/backend/query.py
new file mode 100644
index 0000000..8beb2b9
--- /dev/null
+++ b/contest/backend/query.py
@@ -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 '
boo!
'
+
+
+@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')
diff --git a/contest/results-fetcher.py b/contest/results-fetcher.py
index 4a4e230..c3ef9a3 100755
--- a/contest/results-fetcher.py
+++ b/contest/results-fetcher.py
@@ -82,7 +82,7 @@ def insert_wip(self, remote, run):
else:
data['_id'] = uuid.uuid4().hex
data["remote"] = remote["name"]
- when = datetime.datetime.fromisoformat(branch_info[run['branch']]['date'])
+ when = datetime.datetime.fromisoformat(branch_info['date'])
data["start"] = str(when)
when += datetime.timedelta(hours=2, minutes=58)
data["end"] = str(when)