bep40 commited on
Commit
a98a7e5
·
verified ·
1 Parent(s): 311576b

Upload auto_scheduler.py

Browse files
Files changed (1) hide show
  1. auto_scheduler.py +6 -6
auto_scheduler.py CHANGED
@@ -1,7 +1,7 @@
1
  """VNEWS Auto Scheduler - tự động đăng 3 bài rewrite AI + shorts từ 3 chủ đề HOT
2
  Vào các khung giờ: 7:00, 13:00, 19:00 (giờ Việt Nam)
3
  Mỗi bài: Rewrite AI từ nguồn báo + short video tự động
4
- FIX v6: Use original article title + prepend "Tin tóm tắc VNEWS 7h sáng/13h trưa/19h tối" to text
5
  """
6
  import os, re, json, time, threading, asyncio, logging, random, hashlib, html as html_lib
7
  from datetime import datetime, timezone, timedelta, date
@@ -167,7 +167,7 @@ async def _create_ai_post(topic):
167
  now = datetime.now(VN_TZ)
168
  hour = now.hour
169
  time_label = "7h sáng" if hour == 7 else ("13h trưa" if hour == 13 else "19h tối")
170
- text_intro = f"Tin tóm tắc VNEWS {time_label}"
171
  wall = ai_ext._load_ai_wall()
172
  if not isinstance(wall, list): wall = []
173
  for art in articles:
@@ -176,13 +176,13 @@ async def _create_ai_post(topic):
176
  text = await ai_ext.qwen_generate(prompt, image_url=art.get('image'), max_tokens=1500)
177
  text = ai_patch._postprocess_ai_text(text, max_units=20)
178
  src = [art.get('source', {'title': art.get('title', topic), 'url': art.get('url', ''), 'via': art.get('via', '')})]
179
- # Prepend time label intro to text
180
  if text and not text.startswith(text_intro):
181
  text = f"{text_intro}\n\n{text}"
182
  if 'Nguồn tham khảo:' not in (text or ''):
183
  text = (text or '') + "\n\n" + ai_patch._source_line(src)
184
  img = art.get('image') or ai_ext.pollination_image_url(art.get('title', topic))
185
- # Use original article title instead of time label prefix
186
  post = ai_ext.make_post(art.get('title', topic), text, img, art.get('url', ''), 'auto_scheduled', sources=src)
187
  try:
188
  page_data = ai_patch._scrape_article_images(art.get('url', ''))
@@ -214,7 +214,7 @@ async def _create_fallback_post(topic, ai_ext, ai_patch):
214
  now = datetime.now(VN_TZ)
215
  hour = now.hour
216
  time_label = "7h sáng" if hour == 7 else ("13h trưa" if hour == 13 else "19h tối")
217
- text_intro = f"Tin tóm tắc VNEWS {time_label}"
218
  text = f"{text_intro}\n\n• {topic} đang là chủ đề nóng hôm nay.\n• Theo dõi VNEWS để cập nhật tin tức mới nhất."
219
  img = ai_ext.pollination_image_url(topic)
220
  post = ai_ext.make_post(topic, text, img, '', 'auto_scheduled', sources=[])
@@ -393,4 +393,4 @@ def start_auto_scheduler():
393
  t = threading.Thread(target=_scheduler_loop, daemon=True, name="auto-scheduler")
394
  t.start()
395
  LOG.info("Auto scheduler started")
396
- return t
 
1
  """VNEWS Auto Scheduler - tự động đăng 3 bài rewrite AI + shorts từ 3 chủ đề HOT
2
  Vào các khung giờ: 7:00, 13:00, 19:00 (giờ Việt Nam)
3
  Mỗi bài: Rewrite AI từ nguồn báo + short video tự động
4
+ FIX v7: Giữ nguyên tiêu đề gốc từng bài viết + thêm "Tin tóm tắt VNEWS 7h sáng/13h trưa/19h tối" đầu text
5
  """
6
  import os, re, json, time, threading, asyncio, logging, random, hashlib, html as html_lib
7
  from datetime import datetime, timezone, timedelta, date
 
167
  now = datetime.now(VN_TZ)
168
  hour = now.hour
169
  time_label = "7h sáng" if hour == 7 else ("13h trưa" if hour == 13 else "19h tối")
170
+ text_intro = f"Tin tóm tắt VNEWS {time_label}"
171
  wall = ai_ext._load_ai_wall()
172
  if not isinstance(wall, list): wall = []
173
  for art in articles:
 
176
  text = await ai_ext.qwen_generate(prompt, image_url=art.get('image'), max_tokens=1500)
177
  text = ai_patch._postprocess_ai_text(text, max_units=20)
178
  src = [art.get('source', {'title': art.get('title', topic), 'url': art.get('url', ''), 'via': art.get('via', '')})]
179
+ # Prepend time label intro to text (giữ nguyên title là tiêu đề gốc của bài báo)
180
  if text and not text.startswith(text_intro):
181
  text = f"{text_intro}\n\n{text}"
182
  if 'Nguồn tham khảo:' not in (text or ''):
183
  text = (text or '') + "\n\n" + ai_patch._source_line(src)
184
  img = art.get('image') or ai_ext.pollination_image_url(art.get('title', topic))
185
+ # Dùng art.get('title') GIỮ NGUYÊN tiêu đề gốc từ bài báo
186
  post = ai_ext.make_post(art.get('title', topic), text, img, art.get('url', ''), 'auto_scheduled', sources=src)
187
  try:
188
  page_data = ai_patch._scrape_article_images(art.get('url', ''))
 
214
  now = datetime.now(VN_TZ)
215
  hour = now.hour
216
  time_label = "7h sáng" if hour == 7 else ("13h trưa" if hour == 13 else "19h tối")
217
+ text_intro = f"Tin tóm tắt VNEWS {time_label}"
218
  text = f"{text_intro}\n\n• {topic} đang là chủ đề nóng hôm nay.\n• Theo dõi VNEWS để cập nhật tin tức mới nhất."
219
  img = ai_ext.pollination_image_url(topic)
220
  post = ai_ext.make_post(topic, text, img, '', 'auto_scheduled', sources=[])
 
393
  t = threading.Thread(target=_scheduler_loop, daemon=True, name="auto-scheduler")
394
  t.start()
395
  LOG.info("Auto scheduler started")
396
+ return t