diff --git a/xiaoguo_scanner.py b/xiaoguo_scanner.py index 0907236..3407727 100644 --- a/xiaoguo_scanner.py +++ b/xiaoguo_scanner.py @@ -133,12 +133,20 @@ def search_news(code, max_results=3): return articles -def has_substance(title, content): - """小果LLM判断是否有料(返回 True/False + 情感)""" - text = title + (content or '')[:100] - prompt = f"""新闻:{text} -问:这条新闻跟该股今日上榜有关吗? -回答格式:{"有关":"利好|利空|中性"} 或 "无关" +def check_stock(code, name, articles): + """小果LLM判断这只股票是否有料(一次调用判断所有文章)""" + if not articles: + return None, None + + lines = [f"{i+1}. {a['title']}" for i, a in enumerate(articles[:3])] + prompt = f"""以下是最新关于{name}({code})的新闻标题。 +该股今日上了人气热榜/技术榜单。 + +新闻: +{chr(10).join(lines)} + +这只股上榜是否跟这些新闻有关?有关的话是利好还是利空? +回答格式:有关(利好|利空|中性) 或 无关 回答:""" payload = json.dumps({ @@ -153,14 +161,14 @@ def has_substance(title, content): try: resp = opener.open(req, timeout=30) reply = json.loads(resp.read())["choices"][0]["message"]["content"] - if "有关" in reply: + if "有关" in reply or "利好" in reply or "利空" in reply: for s in ["利好", "利空", "中性"]: if s in reply: return True, s return True, "中性" except: pass - return False, None + return None, None def main(): @@ -209,21 +217,19 @@ def main(): continue has_found = False - for art in articles: - ok, sentiment = has_substance(art["title"], art.get("content", "")) - if ok: - # 有料 → 写入signal_news - conn.execute( - "INSERT INTO signal_news (signal_id, sector, overall_sentiment, summary, key_articles, searched_stocks, source) " - "VALUES (NULL, ?, ?, ?, ?, ?, 'xiaoguo')", - (f"扫描-{name}", sentiment, f"[{sources}] {art['title'][:80]}", - json.dumps([{"title": art["title"], "sentiment": sentiment, "summary": art.get("content","")[:100]}], ensure_ascii=False), - json.dumps([name], ensure_ascii=False)) - ) - has_found = True - found_any = True - print(f" ✅ {name}({code}) [{sources}] {sentiment}: {art['title'][:50]}", flush=True) - break # 一只股有一条有料就够了 + ok, sentiment = check_stock(code, name, articles) + if ok: + has_found = True + found_any = True + sources = "|".join(stock["sources"]) + conn.execute( + "INSERT INTO signal_news (signal_id, sector, overall_sentiment, summary, key_articles, searched_stocks, source) " + "VALUES (NULL, ?, ?, ?, ?, ?, 'xiaoguo')", + (f"扫描-{name}", sentiment, f"[{sources}] {articles[0]['title'][:80]}", + json.dumps([{"title": a["title"], "sentiment": sentiment, "summary": (a.get("content") or "")[:100]} for a in articles[:3]], ensure_ascii=False), + json.dumps([name], ensure_ascii=False)) + ) + print(f" ✅ {name}({code}) [{sources}] {sentiment}: {articles[0]['title'][:50]}", flush=True) mark_scanned(conn, code, name, has_found)