forked from niuniu/llm-intelligence
feat(imports): add real pricing and subscription collectors
Add plan catalog and subscription schema support, seed baselines, and real importers for core domestic subscriptions plus stable official pricing sources. This commit also hardens the shared fetch layers so the importers can support live collection and database writes instead of relying on manual placeholders alone.
This commit is contained in:
56
scripts/catalog_verification_common.go
Normal file
56
scripts/catalog_verification_common.go
Normal file
@@ -0,0 +1,56 @@
|
||||
//go:build llm_script
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
_ "github.com/lib/pq"
|
||||
)
|
||||
|
||||
type catalogVerificationRecord struct {
|
||||
CatalogCode string
|
||||
SourceURL string
|
||||
SourceTitle string
|
||||
PlanStatus string
|
||||
Notes string
|
||||
}
|
||||
|
||||
type catalogVerificationImportConfig struct {
|
||||
URL string
|
||||
Fixture string
|
||||
DryRun bool
|
||||
Timeout time.Duration
|
||||
}
|
||||
|
||||
func upsertCatalogVerificationRecords(db *sql.DB, records []catalogVerificationRecord) error {
|
||||
if len(records) == 0 {
|
||||
return fmt.Errorf("catalog verification records are empty")
|
||||
}
|
||||
for _, record := range records {
|
||||
result, err := db.Exec(
|
||||
`UPDATE plan_catalog_inventory
|
||||
SET source_url = $2,
|
||||
source_title = $3,
|
||||
plan_status = $4,
|
||||
notes = $5,
|
||||
last_checked_at = CURRENT_TIMESTAMP,
|
||||
updated_at = CURRENT_TIMESTAMP
|
||||
WHERE catalog_code = $1`,
|
||||
record.CatalogCode, record.SourceURL, record.SourceTitle, record.PlanStatus, record.Notes,
|
||||
)
|
||||
if err != nil {
|
||||
return fmt.Errorf("update plan_catalog_inventory %s: %w", record.CatalogCode, err)
|
||||
}
|
||||
rowsAffected, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return fmt.Errorf("rows affected for %s: %w", record.CatalogCode, err)
|
||||
}
|
||||
if rowsAffected == 0 {
|
||||
return fmt.Errorf("catalog_code %s not found in plan_catalog_inventory", record.CatalogCode)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user