handler

package
v0.0.0-...-de2cc3d Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var PredictServiceURL = getEnvOrDefault("PREDICT_SERVICE_URL", "http://localhost:5000")

PredictService URL (configured via environment variable)

Functions

func GetPlurkSearch

func GetPlurkSearch(w http.ResponseWriter, r *http.Request)

Cloud Functions handlers

func GetPlurkTop

func GetPlurkTop(w http.ResponseWriter, r *http.Request)

func GetPttSearch

func GetPttSearch(w http.ResponseWriter, r *http.Request)

Cloud Functions handler

func GetPttTrending

func GetPttTrending(w http.ResponseWriter, r *http.Request)

GetPttTrending handles GET /ptt/trending?board=C_Chat&threshold=0.6&mode=all mode: "viral" (已爆文), "potential" (潛在爆文), "all" (兩者都要, 預設)

func ProcessPlurkSearch

func ProcessPlurkSearch(keyword string) (string, error)

func ProcessPlurkTop

func ProcessPlurkTop(qType string) (string, error)

Types

type Article

type Article struct {
	Title   string
	Url     string
	Summary string
}

type Comment

type Comment struct {
	Type    string
	User    string
	Content string
	Time    string
}

Comment represents a PTT comment

type Plurk

type Plurk struct {
	ID      int    `json:"id"`
	Content string `json:"content"`
	Posted  string `json:"posted"`
}

type PredictRequest

type PredictRequest struct {
	Board          string `json:"board"`
	Title          string `json:"title"`
	PostTime       string `json:"post_time"`
	CommentsWindow int    `json:"comments_window"`
	PushWindow     int    `json:"push_window"`
	BooWindow      int    `json:"boo_window"`
	HourOfDay      int    `json:"hour_of_day"`
	DayOfWeek      int    `json:"day_of_week"`
	TitleLength    int    `json:"title_length"`
	HasImage       bool   `json:"has_image"`
	TagType        string `json:"tag_type"`
}

PredictRequest matches the FastAPI service request schema

type PredictResponse

type PredictResponse struct {
	Probability float64 `json:"probability"`
}

PredictResponse from the FastAPI service

type PttParser

type PttParser struct {
	HttpClient *http.Client
}

func NewPttParser

func NewPttParser(client *http.Client) *PttParser

func (*PttParser) FetchArticles

func (p *PttParser) FetchArticles(board string, keyword string) (string, error)

func (*PttParser) FetchTrendingArticles

func (p *PttParser) FetchTrendingArticles(board string, threshold float64, limit int, mode string) (string, error)

FetchTrendingArticles fetches recent articles and predicts viral potential mode: "viral" (已爆文), "potential" (潛在爆文), "all" (兩者都要)

type StatEntry

type StatEntry struct {
	Index int   `json:"index"`
	Stats Stats `json:"stats"`
}

新的 StatEntry 結構

type Stats

type Stats struct {
	PlurkID    int    `json:"plurk_id"`
	Posted     string `json:"posted"`
	Content    string `json:"content"`
	ContentRaw string `json:"content_raw"`
	Owner      struct {
		FullName string `json:"full_name"`
	} `json:"owner"`
}

更新的 Stats 結構

type TrendingArticle

type TrendingArticle struct {
	Article
	Author      string
	PostTime    time.Time
	Comments    []Comment
	Probability float64
	PushCount   int  // 推文數
	IsViral     bool // 是否已爆文 (push >= 100)
}

TrendingArticle extends Article with prediction info

Jump to

Keyboard shortcuts

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