cwadayi commited on
Commit
36495c6
·
verified ·
1 Parent(s): 5f4b7fe

Update usgs_service.py

Browse files
Files changed (1) hide show
  1. usgs_service.py +5 -4
usgs_service.py CHANGED
@@ -18,7 +18,8 @@ def fetch_global_last24h_text(min_mag: float = 5.0, limit: int = 10) -> str:
18
  "endtime": _iso(now_utc),
19
  "minmagnitude": float(min_mag),
20
  "limit": int(limit),
21
- "orderby": "time-desc", # 改為時間倒序,顯示最新的在最上面
 
22
  }
23
  try:
24
  r = requests.get(USGS_API_BASE_URL, params=params, timeout=15)
@@ -32,7 +33,6 @@ def fetch_global_last24h_text(min_mag: float = 5.0, limit: int = 10) -> str:
32
  p = f["properties"]
33
  t_utc = datetime.fromtimestamp(p["time"] / 1000, tz=timezone.utc)
34
 
35
- # [修改] 在訊息中加入 p['url'] 報告連結
36
  lines.append(
37
  f"震級: {p['mag']:.1f} | 日期時間: {t_utc.strftime('%Y-%m-%d %H:%M')} (UTC)\n"
38
  f"地點: {p.get('place', 'N/A')}\n"
@@ -40,7 +40,7 @@ def fetch_global_last24h_text(min_mag: float = 5.0, limit: int = 10) -> str:
40
  )
41
  return "\n\n".join(lines)
42
  except Exception as e:
43
- return f"❌ 查詢失敗: {e}"
44
 
45
  def fetch_taiwan_df_this_year(min_mag: float = 5.0) -> pd.DataFrame | str:
46
  """擷取今年以來台灣區域的顯著地震。"""
@@ -51,7 +51,8 @@ def fetch_taiwan_df_this_year(min_mag: float = 5.0) -> pd.DataFrame | str:
51
  "minmagnitude": float(min_mag),
52
  "minlatitude": 21, "maxlatitude": 26,
53
  "minlongitude": 119, "maxlongitude": 123,
54
- "limit": 250, "orderby": "time-desc",
 
55
  }
56
  try:
57
  r = requests.get(USGS_API_BASE_URL, params=params, timeout=20)
 
18
  "endtime": _iso(now_utc),
19
  "minmagnitude": float(min_mag),
20
  "limit": int(limit),
21
+ # [修正] 將 "time-desc" 改回 API 支援的 "time",此預設即為時間倒序
22
+ "orderby": "time",
23
  }
24
  try:
25
  r = requests.get(USGS_API_BASE_URL, params=params, timeout=15)
 
33
  p = f["properties"]
34
  t_utc = datetime.fromtimestamp(p["time"] / 1000, tz=timezone.utc)
35
 
 
36
  lines.append(
37
  f"震級: {p['mag']:.1f} | 日期時間: {t_utc.strftime('%Y-%m-%d %H:%M')} (UTC)\n"
38
  f"地點: {p.get('place', 'N/A')}\n"
 
40
  )
41
  return "\n\n".join(lines)
42
  except Exception as e:
43
+ return f"❌ 查詢失敗:{e}"
44
 
45
  def fetch_taiwan_df_this_year(min_mag: float = 5.0) -> pd.DataFrame | str:
46
  """擷取今年以來台灣區域的顯著地震。"""
 
51
  "minmagnitude": float(min_mag),
52
  "minlatitude": 21, "maxlatitude": 26,
53
  "minlongitude": 119, "maxlongitude": 123,
54
+ "limit": 250,
55
+ "orderby": "time", # 同樣使用 "time" 預設為時間倒序
56
  }
57
  try:
58
  r = requests.get(USGS_API_BASE_URL, params=params, timeout=20)