Example #1
0
def get_num_news_calls(request):
    ret = {}
    user = get_user(request)

    if is_admin(user):
        ret = {"num_calls": NewsApiInterface.get_num_calls()}

    else:
        return HttpResponseForbidden()
    return HttpResponse(json.dumps(ret))
Example #2
0
def get_news_api_priority(request):
    ret = {}
    user = get_user(request)

    ret = {"news_api_priorities": []}
    if is_admin(user):
        ret["news_api_priorities"] = (
            NewsApiInterface.get_ordered_news_api_list())
    else:
        return HttpResponseForbidden()
    return HttpResponse(json.dumps(ret))
Example #3
0
def set_news_api_priority(request):
    body = json.loads(request.body.decode('utf-8'))
    ret = {}
    user = get_user(request)

    new_news_priorities = body["new_priorities"]
    priorities = []
    if is_admin(user):
        for i in new_news_priorities:
            priorities.append(i['priority'])

        if (len(priorities) > len(set(priorities))):
            return HttpResponseBadRequest()
        else:
            NewsApiInterface.set_news_api_order(new_news_priorities)
            return HttpResponse()
    else:
        return HttpResponseForbidden()

    return HttpResponseBadRequest()
Example #4
0
def get_market_news(request):
    responseData = news_api.get_market_news()
    return HttpResponse(json.dumps(responseData))
Example #5
0
def get_stock_news(request):
    body = json.loads(request.body.decode('utf-8'))
    print(body)
    responseData = news_api.get_news(body['ticker'])
    return HttpResponse(json.dumps(responseData))