parser

package module
v0.0.0-...-022b00e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 17, 2026 License: MIT Imports: 10 Imported by: 0

README

reddit-auto

Reddit parser for w_popularity.

Strategy

  • Primary: public JSON API at https://www.reddit.com/user/<handle>/about.json (channel) and /user/<handle>/submitted.json?limit=50 (recent posts).
  • OAuth (optional): set Config.BearerToken to talk to oauth.reddit.com instead — bumps anon 10 req/min to 100 req/min.
  • No browser fallback needed; Reddit's anonymous JSON endpoints are stable.

Field mapping

Reddit ChannelSnapshot
subreddit.subscribers (preferred) or total_karma (fallback) Followers
total_karma TotalLikes
link_karma, comment_karma, awardee_karma, awarder_karma, is_gold, is_mod, created_utc, icon_img, bio Raw

For posts: score → Likes, num_comments → Comments, permalink → URL.

Caveats

  • Reddit requires a unique, descriptive User-Agent. The default UA (w_popularity/1.0 …) satisfies that. Don't override with a curl-default or you'll get 429s.
  • Personal-subreddit subscriber count (u/<user>) is often 0 for users who never opted into the personal-subreddit feature — that's why karma is the fallback.
  • Anonymous quota: 10 req/min per IP. Use BearerToken for higher limits in production.

Usage

import parser "github.com/suenot/reddit-auto"

p := parser.New(parser.Config{})
snap, err := p.FetchChannel(ctx, "suenot")
posts, err := p.FetchRecentPosts(ctx, "suenot", time.Now().AddDate(0, -1, 0))

License

MIT

Documentation

Overview

Package parser implements the w_popularity Reddit adapter.

Strategy: Reddit's public JSON API at https://www.reddit.com/user/<handle>/about.json (and /submitted.json) exposes karma + recent submissions without auth.

Caveats:

  • Reddit requires a non-default User-Agent or it 429s aggressively. The default UA used here identifies as w_popularity/<host> and is compliant with Reddit's API rules ("unique and descriptive UA").
  • "Followers" doesn't map 1:1 onto a Reddit user. We use Reddit's own personal-subreddit subscriber count (u/<user>) when available (`subreddit.subscribers`); else total_karma as a proxy.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	HTTPClient  *http.Client
	HTTPTimeout time.Duration
	UserAgent   string
	// BaseURL overrides https://www.reddit.com. Test hook.
	BaseURL string
	// BearerToken is an optional Reddit OAuth bearer token. When set, the
	// parser routes to oauth.reddit.com instead of www.reddit.com (which
	// bumps the rate limit from 10 req/min anon to 100 req/min authed).
	// Not required for read-only scraping of public profiles.
	BearerToken string
}

Config controls runtime behaviour.

type RedditParser

type RedditParser struct {
	// contains filtered or unexported fields
}

func New

func New(cfg Config) *RedditParser

func (*RedditParser) FetchChannel

func (p *RedditParser) FetchChannel(ctx context.Context, handle string) (shared.ChannelSnapshot, error)

FetchChannel returns one snapshot for the Reddit user `handle`. Followers = personal-subreddit subscribers if exposed, else total karma.

func (*RedditParser) FetchRecentPosts

func (p *RedditParser) FetchRecentPosts(ctx context.Context, handle string, since time.Time) ([]shared.PostSnapshot, error)

FetchRecentPosts pulls /user/<handle>/submitted.json (last 50 submissions).

func (*RedditParser) Platform

func (p *RedditParser) Platform() shared.Platform

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL