Reddit: posted by hand, with the rules pasted
Reddit's API isn't open to apps like this one, so Supermarket no longer signs in to Reddit, publishes or schedules there, or reads subreddits and the account's posts. The internal/api/reddit client, Reddit's OAuth, its keys and its Social accounts card are gone. Supermarket still writes the post. Each Reddit draft in Posts has a box for its subreddit's rules, with a link to them on Reddit: pasted once, they're kept (subreddits.data, as pasted_rules) and given to the model for later drafts. Open in Reddit saves the edits and opens the submit page filled in; Copy title and Copy text (with the tagged source link) cover a box that comes up empty; Mark as posted records it. Warnings come from the pasted rules and the posts marked as posted. Fill's subreddit suggestions are kept unchecked, and say so. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -12,8 +12,6 @@ import (
|
||||
|
||||
"supermarket/examples"
|
||||
"supermarket/internal/ai"
|
||||
"supermarket/internal/api/reddit"
|
||||
"supermarket/internal/content"
|
||||
"supermarket/internal/inventory"
|
||||
"supermarket/internal/profile"
|
||||
)
|
||||
@@ -39,7 +37,6 @@ type entryData struct {
|
||||
DraftURL string // the address to fill in from
|
||||
Filled []string // after filling in: what was filled
|
||||
Suggestions []inventory.Suggestion
|
||||
CanCheck bool // Reddit could be asked about the suggestions
|
||||
Drafted bool
|
||||
Today string // for new price rows
|
||||
Blank []int // empty price rows to show
|
||||
@@ -179,9 +176,7 @@ func (s *Server) inventoryFill(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(r.Context(), 4*time.Minute)
|
||||
defer cancel()
|
||||
check := s.subredditCheck(ctx)
|
||||
d.CanCheck = check != nil
|
||||
res, err := inventory.Fill(ctx, client, e, d.DraftURL, ours, check)
|
||||
res, err := inventory.Fill(ctx, client, e, d.DraftURL, ours)
|
||||
d.Filled, d.Suggestions, d.Drafted = res.Filled, res.Suggestions, true
|
||||
if err != nil {
|
||||
// Links read before the model failed are kept.
|
||||
@@ -277,30 +272,6 @@ func (s *Server) inventoryExport(w http.ResponseWriter, r *http.Request) {
|
||||
w.Write(data)
|
||||
}
|
||||
|
||||
// subredditCheck looks subreddits up on Reddit for Fill, using the cache
|
||||
// and caching what it reads (drafting for the subreddit uses it later). It's
|
||||
// nil if Reddit can't be asked: no client ID and secret.
|
||||
func (s *Server) subredditCheck(ctx context.Context) inventory.SubredditCheck {
|
||||
c, err := s.redditReader(ctx)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
return func(ctx context.Context, name string) (*reddit.Subreddit, error) {
|
||||
if cached, err := content.GetSubreddit(s.DB, name); err == nil && cached != nil &&
|
||||
time.Since(cached.FetchedAt) < content.SubredditMaxAge {
|
||||
return cached, nil
|
||||
}
|
||||
info, err := c.SubredditInfo(ctx, name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := content.SaveSubreddit(s.DB, info); err != nil {
|
||||
s.Log.Error("caching subreddit", "name", name, "err", err)
|
||||
}
|
||||
return info, nil
|
||||
}
|
||||
}
|
||||
|
||||
// marketRoom says why a new entry can't be added (the plan's limit), or nil.
|
||||
func (s *Server) marketRoom(e *inventory.Entry) error {
|
||||
if e.ID != 0 {
|
||||
|
||||
Reference in New Issue
Block a user