parser

package module
v0.0.0-...-a366471 Latest Latest
Warning

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

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

README

stackoverflow-auto

stackoverflow parser for w_popularity, powered by the Stack Exchange API v2.3.

Strategy

  • Primary: Stack Exchange API v2.3 (site=stackoverflow). No authentication is required. Anonymous quota is 300 requests/day per IP; supplying an app key (Config.AppKey) raises this to 10000/day.
  • Fallback: none.

Endpoints used (all GET, JSON):

  • GET /users/{id}?site=stackoverflow&filter=!)RL-JogHwoZuazwo6-n_WuMc
  • GET /users/{id}/answers?site=stackoverflow&order=desc&sort=creation&pagesize=50
  • GET /users/{id}/questions?site=stackoverflow&order=desc&sort=creation&pagesize=50
Custom user filter

The Stack Exchange default filter omits the per-user totals (view_count, question_count, answer_count, up_vote_count, down_vote_count). A stable custom filter that adds those + envelope diagnostics (backoff, quota_*, error_*) was generated once via /filters/create and is hard-coded as !)RL-JogHwoZuazwo6-n_WuMc.

Handle format

w_popularity stores Stack Overflow handles as "<userid>/<slug>", e.g. "937966/eugen-soloviov". Only the numeric id is sent to the API; the slug is human-readable metadata and is ignored for API calls. A bare numeric id ("937966") is also accepted.

Field mapping

Stack Overflow has no follow graph, so reputation is used as the closest "audience" proxy.

Snapshot field Source
Followers reputation
PostsCount question_count + answer_count
TotalViews view_count (profile views)
TotalLikes up_vote_count
TotalComments 0 (not exposed cleanly per user)
Raw[reputation] reputation
Raw[question_count] question_count
Raw[answer_count] answer_count
Raw[display_name] display_name
Raw[quota_remaining] quota_remaining (from envelope)
Raw[backoff] backoff (only set when API requests one)

Quota & backoff handling

Every Stack Exchange response includes envelope fields backoff and quota_remaining. The parser logs these via log.Printf. error_id=502 ("throttle_violation") maps to shared.ErrRateLimited. backoff > 0 is non-fatal; the value is also surfaced in Raw["backoff"] so callers can decide to wait before the next call.

Usage

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

p := parser.New(parser.Config{AppKey: os.Getenv("STACK_APP_KEY")})

snap, err := p.FetchChannel(ctx, "937966/eugen-soloviov")
posts, err := p.FetchRecentPosts(ctx, "937966/eugen-soloviov", time.Now().AddDate(0, -6, 0))

License

MIT

Documentation

Overview

Package parser implements the w_popularity stackoverflow adapter using the Stack Exchange API v2.3.

Endpoints used (all GET, JSON):

  • /users/{id}?site=stackoverflow
  • /users/{id}/answers?site=stackoverflow&order=desc&sort=creation&pagesize=50
  • /users/{id}/questions?site=stackoverflow&order=desc&sort=creation&pagesize=50

No authentication required. An optional Config.AppKey ("key" query parameter) raises the daily quota from 300 to 10000 requests.

Handle format used by w_popularity: "<userid>/<slug>" e.g. "937966/eugen-soloviov". Only the leading numeric id is sent to the API; the slug is human-readable and ignored for API calls.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// AppKey is the optional "key" query parameter that boosts quota to 10k/day.
	// Leave empty to use the 300/day anonymous quota.
	AppKey string
	// HTTPClient lets tests inject a custom transport.
	HTTPClient *http.Client
	// HTTPTimeout caps every outbound call. Default 15s.
	HTTPTimeout time.Duration
}

Config controls runtime behaviour.

type StackOverflowParser

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

func New

func New(cfg Config) *StackOverflowParser

New constructs a StackOverflowParser ready for use.

func (*StackOverflowParser) FetchChannel

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

FetchChannel returns one snapshot for the user identified by handle.

handle may be either a bare numeric id ("937966") or the canonical "<userid>/<slug>" form used in w_popularity. The slug is ignored.

func (*StackOverflowParser) FetchRecentPosts

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

FetchRecentPosts returns answers + questions authored by user `handle` whose creation_date >= since. Newest-first.

func (*StackOverflowParser) Platform

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

Jump to

Keyboard shortcuts

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