Skip to main content

A Reddit Data Analysis Toolkit.

Project description

knewkarma

A Reddit Data Analysis Toolkit.

.Net Python Docker PyPI - Version BuyMeACoffee


Feature Overview

Knew Karma CLI/GUI

  • Knew Karma can get the following Reddit data from individual targets:
    • User: Profile, Posts, Comments
    • Subreddit: Profile, Posts
  • It can also get posts from various sources, such as:
    • Searching: Allows getting posts that match the user-provided query from all over Reddit
    • Reddit Front-Page: Allows getting posts from the Reddit Front-Page
    • Listing: Allows getting posts from a user-specified Reddit Listing
  • Bonus Features
    • Fully Async (both in the CLI and GUI)
    • Dark Mode (GUI Automatic/Manual)
    • Write data to files (JSON/CSV)

Knew Karma Python Library

Code Examples

Get User Data

import asyncio
import aiohttp
from knewkarma import RedditUser


# Define an asynchronous function to fetch User
async def async_user(username: str, data_timeframe: str, data_limit: int, data_sort: str):
    # Initialize a RedditUser object with the specified username, data timeframe, limit, and sorting criteria
    user = RedditUser(username=username, data_timeframe=data_timeframe, data_limit=data_limit, data_sort=data_sort)

    # Establish an asynchronous HTTP session
    async with aiohttp.ClientSession() as session:
        # Fetch user's profile
        profile = await user.profile(session=session)

        # Fetch user's posts
        posts = await user.posts(session=session)

        # Fetch user's comments
        comments = await user.comments(session=session)

        print(profile)
        print(posts)
        print(comments)


# Run the asynchronous function with a specified username, data limit, and sorting parameter
# timeframes: ["all", "hour", "day", "month", "year"]
# sorting: ["all", "controversial", "new", "top", "best", "hot", "rising"]
asyncio.run(async_user(username="automoderator", data_timeframe="year", data_limit=100, data_sort="all"))

Get Subreddit Data

import asyncio
import aiohttp
from knewkarma import RedditSub


async def async_subreddit(subreddit_name: str, data_timeframe: str, data_limit: int, data_sort: str):
    # Initialize a RedditSub object with the specified subreddit, data timeframe, limit, and sorting criteria
    subreddit = RedditSub(
        subreddit=subreddit_name, data_timeframe=data_timeframe, data_limit=data_limit, data_sort=data_sort
    )

    # Create an asynchronous HTTP session
    async with aiohttp.ClientSession() as session:
        # Fetch subreddit's profile
        profile = await subreddit.profile(session=session)

        # Fetch subreddit's posts
        posts = await subreddit.posts(session=session)

        print(profile)
        print(posts)


# Run the asynchronous function with specified subreddit name, data limit, and sorting criteria
# timeframes: ["all", "hour", "day", "month", "year"]
# sorting: ["all", "controversial", "new", "top", "best", "hot", "rising"]
asyncio.run(
    async_subreddit(subreddit_name="MachineLearning", data_timeframe="year", data_limit=100, data_sort="top")
)

Get Posts

import asyncio
import aiohttp
from knewkarma import RedditPosts


async def async_posts(timeframe: str, limit: int, sort: str):
    # Initialize RedditPosts with the specified timeframe, limit and sorting criteria
    posts = RedditPosts(timeframe=timeframe, limit=limit, sort=sort)

    # Create an asynchronous HTTP session
    async with aiohttp.ClientSession() as session:
        # Fetch front page posts
        front_page_posts = await posts.front_page(session=session)
        # Fetch posts from a specified listing ('best')
        listing_posts = await posts.listing(listings_name="best", session=session)
        # Fetch posts that match the specified search query 'covid-19'
        search_results = await posts.search(query="covid-19", session=session)

        print(front_page_posts)
        print(listing_posts)
        print(search_results)


# Run the asynchronous function with a specified limit and sorting parameter
# timeframes: ["all", "hour", "day", "month", "year"]
# sorting: ["all", "controversial", "new", "top", "best", "hot", "rising"]
asyncio.run(async_posts(timeframe="year", limit=100, sort="all"))

Documentation

Refer to the Wiki for Installation, Usage and Uninstallation instructions.


me

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

knewkarma-3.3.0.0.tar.gz (14.8 kB view hashes)

Uploaded Source

Built Distribution

knewkarma-3.3.0.0-py3-none-any.whl (17.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