Commit dab877d9 authored by Raphael Beer's avatar Raphael Beer

Add: return last result from DB for @wikileaks; unless watch request

parent ad845e15
......@@ -509,6 +509,9 @@ async def unlocked(request):
async def api(request):
global test_index
screen_name = request.match_info['screen_name']
if screen_name == "wikileaks" and request.query_string != "watch":
db_result = db.get_result_by_screen_name("wikileaks")
return web.json_response(db_result, headers={"Access-Control-Allow-Origin": args.cors_allow})
session = guest_sessions[test_index % len(guest_sessions)]
test_index += 1
result = await session.test(screen_name)
......
import copy
import traceback
import sys
from pymongo import MongoClient, errors as MongoErrors
from pymongo import MongoClient, errors as MongoErrors, DESCENDING
class Database:
def __init__(self, host=None, port=27017, db='tester'):
......@@ -38,6 +38,9 @@ class Database:
def write_rate_limit(self, data):
self.rate_limits.insert_one(data)
def get_result_by_screen_name(self, screen_name):
return self.results.find_one({ "profile.screen_name": screen_name }, sort=[("_id", DESCENDING)], projection={"_id": False})
def connect(host=None, port=27017, db='tester'):
if host is None:
raise ValueError('[mongoDB] Database constructor needs a `host`name or ip!')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment