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.
114 lines
4.1 KiB
Go
114 lines
4.1 KiB
Go
//go:build llm_script
|
||
|
||
package main
|
||
|
||
import (
|
||
"fmt"
|
||
"regexp"
|
||
"strings"
|
||
)
|
||
|
||
const (
|
||
defaultBaiduCodingPlanURL = "https://cloud.baidu.com/doc/qianfan/s/imlg0beiu"
|
||
defaultBaiduTokenPlanURL = "https://cloud.baidu.com/doc/qianfan/s/Smoghsq3g"
|
||
)
|
||
|
||
func parseBaiduSubscriptionCatalog(codingRaw string, tokenRaw string) ([]subscriptionImportRecord, error) {
|
||
publishedAt, known := publishedAtFromText(firstNonEmptyText(codingRaw, tokenRaw))
|
||
codingRecords, err := parseBaiduCodingPlan(codingRaw, publishedAt)
|
||
if err != nil {
|
||
return nil, err
|
||
}
|
||
tokenRecords, err := parseBaiduTokenBenefitPack(tokenRaw, publishedAt)
|
||
if err != nil {
|
||
return nil, err
|
||
}
|
||
records := append(codingRecords, tokenRecords...)
|
||
for i := range records {
|
||
records[i].PublishedAtKnown = known
|
||
}
|
||
return records, nil
|
||
}
|
||
|
||
func parseBaiduCodingPlan(raw string, publishedAt string) ([]subscriptionImportRecord, error) {
|
||
pattern := regexp.MustCompile(`Coding Plan (Lite|Pro)\s+¥\s*([\d,]+)\s*/\s*月\s+每 5 小时:最多约 [\d,]+ 次请求\s+每周:最多约 [\d,]+ 次请求\s+每订阅月:最多约 ([\d,]+) 次请求`)
|
||
matches := pattern.FindAllStringSubmatch(raw, -1)
|
||
if len(matches) != 2 {
|
||
return nil, fmt.Errorf("unexpected baidu coding plan count: %d", len(matches))
|
||
}
|
||
|
||
records := make([]subscriptionImportRecord, 0, len(matches))
|
||
for _, match := range matches {
|
||
tier := match[1]
|
||
records = append(records, subscriptionImportRecord{
|
||
ProviderName: "Baidu",
|
||
ProviderNameCn: "百度",
|
||
ProviderCountry: "CN",
|
||
ProviderWebsite: "https://cloud.baidu.com",
|
||
OperatorName: "Baidu Qianfan",
|
||
OperatorNameCn: "百度千帆",
|
||
OperatorCountry: "CN",
|
||
OperatorWebsite: "https://cloud.baidu.com/doc/qianfan/index.html",
|
||
OperatorType: "cloud",
|
||
PlanFamily: "coding_plan",
|
||
PlanCode: "baidu-coding-plan-" + strings.ToLower(tier),
|
||
PlanName: "千帆 Coding Plan " + tier,
|
||
Tier: tier,
|
||
BillingCycle: "monthly",
|
||
Currency: "CNY",
|
||
ListPrice: mustParseSubscriptionPrice(match[2]),
|
||
PriceUnit: "CNY/month",
|
||
QuotaValue: mustParseSubscriptionInt64(match[3]),
|
||
QuotaUnit: "requests/month",
|
||
PlanScope: "Coding Plan",
|
||
SourceURL: defaultBaiduCodingPlanURL,
|
||
PublishedAt: publishedAt,
|
||
EffectiveDate: effectiveDateFromPublishedAt(publishedAt),
|
||
Notes: "额度按 5 小时、每周、每订阅月三重窗口刷新。",
|
||
})
|
||
}
|
||
return records, nil
|
||
}
|
||
|
||
func parseBaiduTokenBenefitPack(raw string, publishedAt string) ([]subscriptionImportRecord, error) {
|
||
pattern := regexp.MustCompile(`(\d{2,3},\d{3})\s+1个月\s+¥(\d+)\s+¥(\d+)`)
|
||
matches := pattern.FindAllStringSubmatch(raw, -1)
|
||
if len(matches) != 5 {
|
||
return nil, fmt.Errorf("unexpected baidu token benefit pack count: %d", len(matches))
|
||
}
|
||
|
||
records := make([]subscriptionImportRecord, 0, len(matches))
|
||
for _, match := range matches {
|
||
quota := mustParseSubscriptionInt64(match[1])
|
||
originalPrice := strings.TrimSpace(match[2])
|
||
promoPrice := strings.TrimSpace(match[3])
|
||
records = append(records, subscriptionImportRecord{
|
||
ProviderName: "Baidu",
|
||
ProviderNameCn: "百度",
|
||
ProviderCountry: "CN",
|
||
ProviderWebsite: "https://cloud.baidu.com",
|
||
OperatorName: "Baidu Qianfan",
|
||
OperatorNameCn: "百度千帆",
|
||
OperatorCountry: "CN",
|
||
OperatorWebsite: "https://cloud.baidu.com/doc/qianfan/index.html",
|
||
OperatorType: "cloud",
|
||
PlanFamily: "token_plan",
|
||
PlanCode: fmt.Sprintf("baidu-token-benefit-pack-%d", quota),
|
||
PlanName: fmt.Sprintf("千帆 Token 福利包 %d", quota),
|
||
Tier: fmt.Sprintf("%d", quota),
|
||
BillingCycle: "monthly",
|
||
Currency: "CNY",
|
||
ListPrice: mustParseSubscriptionPrice(promoPrice),
|
||
PriceUnit: "CNY/pack",
|
||
QuotaValue: quota,
|
||
QuotaUnit: "credits/pack",
|
||
PlanScope: "Token 福利包",
|
||
SourceURL: defaultBaiduTokenPlanURL,
|
||
PublishedAt: publishedAt,
|
||
EffectiveDate: effectiveDateFromPublishedAt(publishedAt),
|
||
Notes: fmt.Sprintf("首购优惠价 ¥%s,原价 ¥%s,有效期 1 个月。", promoPrice, originalPrice),
|
||
})
|
||
}
|
||
return records, nil
|
||
}
|