Skip to main content

Retrieve public data from 'sololearn.com'.

Project description

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.

  • Get courses info and lessons data.

  • Retrieve 'Hot Today' discussions.

  • Find out what are the trending, most recent and unanswered discussions.

Tech

sololearnlib just uses bs4 (BeautifulSoup4).

Installation

sololearnlib requires Python 3 v3.5+ to run.

$ pip install sololearnlib

Usage

Retrieve Blog data

  • Import
from sololearnlib.sololearn import Blog
  • Create a class object.
blog = Blog()
  • After creating an object you can use some of its attributes.
print(blog.domain)
# "https://www.sololearn.com"
  • Using methods/functions
articles = blog.get_articles()
# [{'article_link': '/Blog/73/habit-formi...-learning/', 'content': ' \xa0For most of us, th...ss time.\xa0 ', 'date': '07 August 2020', 'image_link': 'https://api.sololear...ning_1.jpg', 'title': 'Habit-Forming Learni...d Learning'}, ...]

# Get the link of first article.
article_link = articles[0]["article_link"]
# '/Blog/73/habit-forming-learning-vs-forced-learning/'

full_text = blog.get_full_article(article_link)
# '\n\nDo you struggle when learning new things? Most people do -- even when receiving a formal education in school or attending college, it can be hard to make new concepts stick. ...'

Retrieve Code Playground Data

  • Import
from sololearnlib.sololearn import CodePlayground
  • Create a class object.
ground = CodePlayground()
  • After creating an object you can use some of its attributes.
print(ground.hot_today)
# [{'Web Dev Quiz': 'https://code.sololea...zpmPj7kP/#'}, ...]
  • Using methods/functions
codes = ground.get_codes()
# [{'author_link': '/Profile/12942084', 'author_name': 'Aakaanksha 💕', 'code_link': 'https://code.sololea...oj07HPmq/#', 'code_name': 'Google Clone or Real? 😳💕', 'data_date': '8/9/2020 7:36:06 AM', 'votes': 1146},  ...]

Retrieve Courses Data

  • Import
from sololearnlib.sololearn import Courses
  • Create a class object.
courses = Courses()
  • After creating an object you can use some of its attributes.
print(courses.courses)
# {'c': {'counts': {...}, 'description': '\nOur C tutorial cove...uch more.\n', 'icon': '/Icons/Courses/1089.png', 'link': '/Course/C/', 'title': 'C Tutorial'}, ...}
  • Using methods/functions
lessons = courses.get_lessons("python")
# {'Basic Concepts': ['Welcome to Python', 'Your First Program', 'Simple Operations', 'Floats', 'Other Numerical Operations', 'Strings', 'String Operations', 'Variables', 'Taking User Input', ...], ...}

Retrieve Discuss Data

  • Import
from sololearnlib.sololearn import Discuss
  • Create a class object.
dis = Discuss()
  • After creating an object you can use some of its attributes.
print(dis.hot_today)
# [{'[SOLVED]C++ Challenge problem': '/Discuss/2437254/sol...e-problem/'}, {'[Solved] Does Earnin...ves us XP?': '/Discuss/2437589/sol...ves-us-xp/'}, ...]
  • Using methods/functions
posts = dis.get_posts()
# [{'answers': '24716', 'author_link': '/Profile/5056131/', 'author_name': 'benka', 'avatar_link': 'https://avatars.solo...b873e5.jpg', 'data_date': '7/6/2017 5:02:16 PM', 'post_link': '/Discuss/516185/мног...оговорящих', 'tags': [...], 'title': 'много ли тут нас, ру...говорящих?', 'votes': '1199'}, ...]

Retrieve Top Learners Data

  • Import
from sololearnlib.sololearn 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)
# {'1': {'name': 'JΞΜΔ 🇨🇩👑', 'points': 1070064}, ...}

print(top.leaderboard_title)
# 'Global Leaderboard'
  • Using methods/functions
board = top.get_leaderboard("python")
# {'1': {'name': '👑 Prometheus 🇸🇬', 'points': 193985}, ...}

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!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sololearnlib-3.0.0.tar.gz (10.2 kB view hashes)

Uploaded Source

Built Distribution

sololearnlib-3.0.0-py3-none-any.whl (8.9 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page