raghavNCI commited on
Commit
5557673
Β·
1 Parent(s): b2bd47e

newsdata url correction

Browse files
Files changed (1) hide show
  1. nuse_modules/headlines_generator.py +11 -4
nuse_modules/headlines_generator.py CHANGED
@@ -37,25 +37,32 @@ _REQUEST_TIMEOUT = 10
37
  # NEWSDATA FETCHER
38
  # ──────────────────────────────────────────────────────────────
39
  def _newsdata_url(
40
- category: str,
41
- query: Optional[str] = None,
 
42
  page: int = 0,
43
  language: str = "en",
44
  size: int = 25,
45
  ) -> str:
 
 
 
 
46
  base = (
47
- "https://newsdata.io/api/1/news"
48
  f"?apikey={NEWSDATA_API_KEY}"
49
  f"&language={language}"
50
- f"&category={category}"
51
  f"&size={size}"
52
  f"&page={page}"
53
  )
54
  if query:
55
  base += f"&q={query}"
 
 
56
  return base
57
 
58
 
 
59
  def _fetch_newsdata_articles(cat_key: str, category: str, wanted: int) -> List[dict]:
60
  """
61
  Fetch up to `wanted` articles for a given logical category (cat_key).
 
37
  # NEWSDATA FETCHER
38
  # ──────────────────────────────────────────────────────────────
39
  def _newsdata_url(
40
+ *, # ← keyword-only for clarity
41
+ query: str | None = None,
42
+ category: str | None = None,
43
  page: int = 0,
44
  language: str = "en",
45
  size: int = 25,
46
  ) -> str:
47
+ """
48
+ Build the /latest endpoint URL.
49
+ You may supply *either* query OR category (not both).
50
+ """
51
  base = (
52
+ "https://newsdata.io/api/1/latest"
53
  f"?apikey={NEWSDATA_API_KEY}"
54
  f"&language={language}"
 
55
  f"&size={size}"
56
  f"&page={page}"
57
  )
58
  if query:
59
  base += f"&q={query}"
60
+ elif category:
61
+ base += f"&category={category}"
62
  return base
63
 
64
 
65
+
66
  def _fetch_newsdata_articles(cat_key: str, category: str, wanted: int) -> List[dict]:
67
  """
68
  Fetch up to `wanted` articles for a given logical category (cat_key).