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):
# Initialize RedditUser with the specified username
user = RedditUser(username=username)
# Establish an asynchronous HTTP session
async with aiohttp.ClientSession() as session:
# Fetch user's profile
profile = await user.profile(session=session)
# timeframes: ["hour", "day", "month", "year"]. Leave parameter unspecified to get from all timeframes.
# sorting: ["controversial", "new", "top", "best", "hot", "rising"]. Leave parameter unspecified to get from all sort criteria.
# Fetch user's posts
posts = await user.posts(limit=200, sort="top", timeframe="year",
session=session)
# Fetch user's comments
comments = await user.comments(limit=200, sort="top", timeframe="year",
session=session)
print(profile)
print(posts)
print(comments)
asyncio.run(async_user(username="automoderator"))
Get Subreddit Data
import asyncio
import aiohttp
from knewkarma import RedditSub
async def async_subreddit(subreddit_name: str):
# Initialize RedditSub with the specified subreddit
subreddit = RedditSub(
subreddit=subreddit_name)
# 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
# timeframes: ["hour", "day", "month", "year"]. Leave parameter unspecified to get from all timeframes.
# sorting: ["controversial", "new", "top", "best", "hot", "rising"]. Leave parameter unspecified to get from all sort criteria.
posts = await subreddit.posts(limit=100, sort="top", timeframe="month", session=session)
print(profile)
print(posts)
asyncio.run(
async_subreddit(subreddit_name="MachineLearning")
)
Get Posts
import asyncio
import aiohttp
from knewkarma import RedditPosts
async def async_posts():
# Initialize RedditPosts
posts = RedditPosts()
# Create an asynchronous HTTP session
async with aiohttp.ClientSession() as session:
# timeframes: ["hour", "day", "month", "year"]. Leave parameter unspecified to get from all timeframes.
# sorting: ["controversial", "new", "top", "best", "hot", "rising"]. Leave parameter unspecified to get from all sort criteria.
# Fetch front page posts
front_page_posts = await posts.front_page(limit=50, sort="top", timeframe="hour", session=session)
# Fetch posts from a specified listing ('best')
listing_posts = await posts.listing(listings_name="best", limit=50, sort="best", timeframe="month",
session=session)
# Fetch posts that match the specified search query 'covid-19'
search_results = await posts.search(query="covid-19", limit=300, session=session)
print(front_page_posts)
print(listing_posts)
print(search_results)
asyncio.run(async_posts())
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.5.0.0.tar.gz
(14.2 kB
view hashes)
Built Distribution
Close
Hashes for knewkarma-3.5.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 200aa2befe3dae8347f4b0e8e15b3788844abcb2b41e727dc67fdb16ed528cbe |
|
MD5 | 1ed962cad8ce1c7c40feb2a38a658701 |
|
BLAKE2b-256 | 2e7b16945297be42f2c5c1cca65615e7de7a873d75baa3ca402648a02d7b8d85 |