@@ -0,0 +1,2378 @@
+# Run with Python 3%0Aimport collections%0Aimport json%0Aimport operator%0Aimport requests%0Aimport urllib%0A%0A# 1. Get your keys at https://stepic.org/oauth2/applications/ (client type = confidential,%0A# authorization grant type = client credentials)%0Aclient_id = %22...%22%0Aclient_secret = %22...%22%0A%0A# 2. Get a token%0Aauth = requests.auth.HTTPBasicAuth(client_id, client_secret)%0Aresp = requests.post(%0A    'https://stepic.org/oauth2/token/',%0A    data=%7B'grant_type': 'client_credentials'%7D,%0A    auth=auth%0A)%0Aresponse = json.loads(resp.text)%0Atoken = response.get('access_token')%0A%0Aif not token:%0A    print('Auth unsuccessful')%0A    exit(0)%0A%0A%0A# 3. Call API (https://stepic.org/api/docs/) using this token.%0A# Example:%0A%0Adef load_api(method, **kwargs):%0A    api_url = 'https://stepic.org:443/api/'%0A    params = urllib.parse.urlencode(kwargs)%0A    return json.loads(requests.get(%0A        api_url + method + '/?' + params,%0A        headers=%7B'Authorization': 'Bearer ' + token%7D).text%0A    )%0A%0A# Get top lessons by reaction on recommendations%0A%0ANUM_OF_REACTION_PAGES = 100%0ANUM_OF_REACTION_TOP = 10%0A%0Alessons_method = 'lessons'%0Arecommendation_reactions_method = 'recommendation-reactions'%0A%0A%0Adef print_status(message, done, total):%0A    print('%7B%7D: %7B%7D/%7B%7D'.format(message, done, total), end='%5Cr' if done != total else '%5Cn')%0A%0Acourse_reactons = collections.defaultdict(int)%0A%0Afor i in range(NUM_OF_REACTION_PAGES):%0A    print_status('Loading', i+1, NUM_OF_REACTION_PAGES)%0A    response = load_api(recommendation_reactions_method, page=i+1)%0A%0A    for reaction in response.get('recommendation-reactions'):%0A        value = reaction.get('reaction')%0A        course_reactons%5Breaction.get('lesson')%5D += value if value %3E 0 else -value - 1%0A%0A    if not response.get('meta').get('has_next'):%0A        break%0A%0A%0Asorted_lessons = sorted(course_reactons.items(), key=operator.itemgetter(1), reverse=True)%0A%0A# Add all equal to the last%0Awhile len(sorted_lessons) != NUM_OF_REACTION_TOP and %5C%0A      sorted_lessons%5BNUM_OF_REACTION_TOP%5D%5B1%5D == sorted_lessons%5BNUM_OF_REACTION_TOP - 1%5D%5B1%5D:%0A    NUM_OF_REACTION_TOP += 1%0A%0Aprint('Top lessons by reaction')%0Aprint('(Title: reaction value)')%0Aprint()%0A%0Afor lesson_id in sorted_lessons%5B:min(NUM_OF_REACTION_TOP, len(sorted_lessons))%5D:%0A    response = response = load_api('%7B%7D/%7B%7D'.format(lessons_method, lesson_id%5B0%5D))%0A    lesson = response.get('lessons')%5B0%5D%0A%0A    print('%7B%7D: %7B%7D'.format(lesson.get('title'), lesson_id%5B1%5D))%0A

Add example