示例#1
0
def list(request):
    try:
        parameters = request.GET.dict()
        validate_optional_parameters(parameters, ['since', 'limit', 'order'], [None, None, 'desc'])
        if 'forum' in parameters and 'thread' not in parameters:
            from API.requests import forum_requests

            posts = forum_requests.getPostsList(parameters['forum'], parameters['since'],
                                               parameters['order'], parameters['limit'], [])
        elif 'thread' in parameters and 'forum' not in parameters:
            from API.requests import thread_requests

            posts = thread_requests.getPostsList(parameters['thread'], parameters['since'],
                                                parameters['order'], parameters['limit'])
        else:
            raise Exception("Wrong required parameters")
        response_json = {
            'code': 0,
            'response': posts,
        }
    except Exception as e:
        response_json = {
            'code': 1,
            'response': str(e),
        }
    return HttpResponse(json.dumps(response_json, ensure_ascii=False), content_type='application/json')
示例#2
0
def listPosts(request):
    try:
        parameters = request.GET.dict()
        validate_required_parameters(parameters, ["thread"])
        validate_optional_parameters(parameters, ["since", "limit", "order"], [None, None, "desc"])
        threads = thread_requests.getPostsList(
            parameters["thread"], parameters["since"], parameters["order"], parameters["limit"]
        )
        response_json = {"code": 0, "response": threads}
    except Exception as e:
        response_json = {"code": 1, "response": str(e)}
    return HttpResponse(json.dumps(response_json, ensure_ascii=False), content_type="application/json")