Files
llm-intelligence/scripts/import_mobile_cloud_catalog.go
phamnazage-jpg 958245537a 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.
2026-05-15 22:32:57 +08:00

95 lines
2.5 KiB
Go

//go:build llm_script
package main
import (
"database/sql"
"flag"
"fmt"
"io"
"net/http"
"os"
"strings"
"time"
)
const defaultMobileCloudCatalogURL = "https://saas.ecloud.10086.cn/Store/List"
func main() {
loadSubscriptionImportEnv()
var url string
var fixture string
var dryRun bool
var timeoutSeconds int
flag.StringVar(&url, "url", defaultMobileCloudCatalogURL, "移动云 AI 应用专区 URL")
flag.StringVar(&fixture, "fixture", "", "移动云 AI 应用专区样例文件")
flag.BoolVar(&dryRun, "dry-run", false, "仅校验并打印摘要,不写入数据库")
flag.IntVar(&timeoutSeconds, "timeout", 20, "请求超时(秒)")
flag.Parse()
cfg := catalogVerificationImportConfig{
URL: url,
Fixture: fixture,
DryRun: dryRun,
Timeout: time.Duration(timeoutSeconds) * time.Second,
}
var db *sql.DB
var err error
if !cfg.DryRun {
db, err = subscriptionImportDB()
if err != nil {
fmt.Fprintf(os.Stderr, "open db: %v\n", err)
os.Exit(1)
}
defer db.Close()
}
if err := runMobileCloudCatalogImport(cfg, db, os.Stdout); err != nil {
fmt.Fprintf(os.Stderr, "import_mobile_cloud_catalog: %v\n", err)
os.Exit(1)
}
}
func parseMobileCloudCatalog(raw string) ([]catalogVerificationRecord, error) {
if !strings.Contains(raw, "AI应用专区") {
return nil, fmt.Errorf("mobile cloud AI market marker not found")
}
if !strings.Contains(raw, "数据大模型") {
return nil, fmt.Errorf("mobile cloud data model marker not found")
}
return []catalogVerificationRecord{{
CatalogCode: "mobile-cloud-ai-market",
SourceURL: defaultMobileCloudCatalogURL,
SourceTitle: "移动云市场 AI 应用专区",
PlanStatus: "confirmed",
Notes: "官方云市场已公开展示 AI 应用专区,覆盖数据大模型等类目,但统一编程套餐价格仍未公开披露。",
}}, nil
}
func runMobileCloudCatalogImport(cfg catalogVerificationImportConfig, db *sql.DB, out io.Writer) error {
client := &http.Client{Timeout: cfg.Timeout}
raw, err := fetchSubscriptionPage(cfg.URL, cfg.Fixture, client)
if err != nil {
return err
}
records, err := parseMobileCloudCatalog(raw)
if err != nil {
return err
}
if cfg.DryRun {
_, err = fmt.Fprintf(out, "source=mobile-cloud-catalog-import entries=%d dry_run=true\n", len(records))
return err
}
if db == nil {
return fmt.Errorf("db is required when dry-run=false")
}
if err := upsertCatalogVerificationRecords(db, records); err != nil {
return err
}
_, err = fmt.Fprintf(out, "source=mobile-cloud-catalog-import entries=%d dry_run=false\n", len(records))
return err
}