Okay, here is the problem:
Certain questions contain more than one page's worth of answers. Given a sort method and an answer id, how can we figure out which page the answer is on?
Any suggestions are welcome.
Stack Apps is a question and answer site for apps, scripts, and development with the Stack Exchange API. It only takes a minute to sign up.Sign up to join this community
These are two simple methods in meta-language:
1. Pulls a pagesize number of answers, page after page, checking the presence of the given accepted_answer_id
def get_accepted_answer_page(question_id, answer_id, sort, pagesize): page = 1 while(True): answers_page_ids = get_answers_ids_with_API_method(question_id, sort, page, pagesize) if accepted_answer_id in answers_page_ids : return page else: page ++
2. Pulls all the answers ids using the fastest/lightest API method (questions/id/answers, pagesize=100, body=false..), get the index of the accepted_answer_id on this list and finally find the page dividing accepted_answer_id position by the pagesize
def get_accepted_answer_page(question_id, answer_id, sort, pagesize): answers_ids = get_all_answers_ids_with_the_fastest_lightest_API_method(question_id, sort) accepted_answer_id_position = get_accepted_answer_index (answers_ids) + 1 accepted_answer_page = (accepted_answer_id_position / pagesize) +1 if accepted_answer_id_index MOD pagesize == 0 : accepted_answer_page -- return accepted_answer_page