A Reddit Data Analysis Toolkit.
Project description
A Reddit Data Analysis Toolkit.
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.
Project details
Release history Release notifications | RSS feed
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)
Built Distribution
Close
Hashes for knewkarma-3.3.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 560e85f673a74cf0a5d8b7212850302e9a4639061a373354428a69803fd39c45 |
|
MD5 | ee4cc30382a8e95e73ec5268e1668853 |
|
BLAKE2b-256 | 9c48f19b2a058aae9dd2a424670e6e027af4ec1d8310e2f98352e8a2dee20338 |