mirror of
https://github.com/openai/openai-cookbook
synced 2024-11-19 15:25:37 +00:00
changes search date to June 2023
This commit is contained in:
parent
03e74bb9a4
commit
e56364d126
@ -192,18 +192,22 @@
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"def search_news(query: str):\n",
|
||||
" # get date 1 week ago\n",
|
||||
" one_week_ago = (date.today() - timedelta(weeks=1)).strftime(\"%Y-%m-%d\")\n",
|
||||
"\n",
|
||||
"def search_news(\n",
|
||||
" query: str,\n",
|
||||
" news_api_key: str = news_api_key,\n",
|
||||
" num_articles: int = 50,\n",
|
||||
" from_datetime: str = \"2023-06-01\", # the 2023 NBA finals were played in June 2023\n",
|
||||
" to_datetime: str = \"2023-06-30\",\n",
|
||||
") -> dict:\n",
|
||||
" response = requests.get(\n",
|
||||
" \"https://newsapi.org/v2/everything\",\n",
|
||||
" params={\n",
|
||||
" \"q\": query,\n",
|
||||
" \"apiKey\": news_api_key,\n",
|
||||
" \"pageSize\": 50,\n",
|
||||
" \"pageSize\": num_articles,\n",
|
||||
" \"sortBy\": \"relevancy\",\n",
|
||||
" \"from\": one_week_ago,\n",
|
||||
" \"from\": from_datetime,\n",
|
||||
" \"to\": to_datetime,\n",
|
||||
" },\n",
|
||||
" )\n",
|
||||
"\n",
|
||||
@ -217,7 +221,7 @@
|
||||
" if result[\"status\"] == \"ok\":\n",
|
||||
" articles = articles + result[\"articles\"]\n",
|
||||
" else:\n",
|
||||
" raise Exception(result[\"message\"])"
|
||||
" raise Exception(result[\"message\"])\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user