Skip to content

Or-i0n/sololearnlib

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sololearnlib

sololearnlib is a library for retrieving public data from Sololearn.

  • Easy to use.
  • Lightweight.
  • Object Oriented.
  • Json-compatible data.

Features

  • Retrieve Blog articles.
  • Get Leaderboard data.
  • Retrieve 'Hot Today' codes from Code Playground.
  • Find out what are the trending, most recent and most popular codes.
  • Retrieve 'Hot Today' discussions.
  • Find out what are the trending, most recent and unanswered discussions.

Tech

sololearn just uses bs4 (BeautifulSoup4).

Installation

sololearnlib requires Python 3 v3.5+ to run.

$ pip install sololearnlib

Usage

Retrieve Blog data

  • Import
from sololearnlib import Blog
  • Create a class object.
blog = Blog()
  • Using methods/functions
# Get data about all the articles.
articles = blog.get_articles()
# {'getTopics': {'success': 1, 'errors': [...], 'data': [...]},
#  'getBlogPosts': {'paging': {...}, 'success': 1, 'errors': 
#   [...], 'data': [...]}}

Retrieve Code Playground Data

  • Import
from sololearnlib import CodePlayground
  • Create a class object.
ground = CodePlayground()
  • Using methods/functions
# Get hot codes.
hot = ground.get_hot_today()
# [{'😄Pure css Emoji😄😊': 'https://code.sololearn.com
#   /WVo6hshrJ3p6/#'}, {'⚔️Assasin Custom UI Cover ⚔️': 
#   'https://code.sololearn.com/WdNImK2M9ush/#'}, ...]

# Get all other codes.
codes = ground.get_codes()
# [{'code_link': 'https://code.sololearn.com/WZmG081162lG/#',
#   'code_name': 'Water sort puzzle game 🔥', 'votes': 638, 
#   'author_name': 'Namit Jain [INACTIVE]', 'author_link': 
#   '/Profile/18109487', 'data_date': '4/23/2021 6:17:25 AM'}, 
#   ...]

Retrieve Discuss Data

  • Import
from sololearnlib import Discuss
  • Create a class object.
dis = Discuss()
  • Using methods/functions
# Get posts available for discussion.
posts = dis.get_posts()
# [{'votes': '0', 'answers': '0', 'post_link': '/Discuss/2760604
#   /trying-to-pull-individual-values-from-a-dataframe-but-pulls-
#   arrays-instead', 'title': 'Trying to pull individual values 
#    from a dataframe but pulls arrays instead', 'tags': [...],
#   'author_name': 'Hernando Abella', 'author_link': '/Profile
#   /1478871/', 'data_date': '4/20/2021 4:12:36 PM', 
#   'avatar_link': 'https://blob.sololearn.com/avatars/e97c267a-
#    e433-4c47-81f3-6d32dcd30570.jpg'}, ...]

# Trending topics on discussions.
hot_discuss = dis.get_hot_today()
# [{'Can we obtain graphs in node code here at sololearn ?': 
#   '/Discuss/2784363/can-we-obtain-graphs-in-node-code-here-at-
#   sololearn/'}, {'Why R code is necessary?': '/Discuss/2784479
#   /why-r-code-is-necessary/'}, ...]

Retrieve Top Learners Data

  • Import
from sololearnlib import TopLearners
  • Create a class object.
top = TopLearners()
  • After creating an object you can use some of its attributes.
print(top.courses)
# {'c': {'link': '/Leaderboard/C', 'title': 'C Tutorial'}, ...}

print(top.leaderboard_title)
# 'Global Leaderboard'
  • Using methods/functions
# List of user who top the 'react' leaderboard.
board = top.get_leaderboard("react")
# {'1': {'name': 'Arthur', 'points': 2000}, '2': {'name': 
#  'Accountz5', 'points': 794}, '3': {'name': 'Hayk Tester1', 
#  'points': 760}, ...}

Development

Want to contribute? Great!

Head toward the github repository:

Todos

  • Write MORE Tests.

  • Add error handling.

  • Make retrieval time faster.

License


MIT

Free Software, Hell Yeah!