changes search date to June 2023

This commit is contained in:
Ted Sanders 2023-06-16 16:34:58 -07:00
parent 03e74bb9a4
commit e56364d126

View File

@ -192,18 +192,22 @@
} }
], ],
"source": [ "source": [
"def search_news(query: str):\n", "def search_news(\n",
" # get date 1 week ago\n", " query: str,\n",
" one_week_ago = (date.today() - timedelta(weeks=1)).strftime(\"%Y-%m-%d\")\n", " news_api_key: str = news_api_key,\n",
"\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", " response = requests.get(\n",
" \"https://newsapi.org/v2/everything\",\n", " \"https://newsapi.org/v2/everything\",\n",
" params={\n", " params={\n",
" \"q\": query,\n", " \"q\": query,\n",
" \"apiKey\": news_api_key,\n", " \"apiKey\": news_api_key,\n",
" \"pageSize\": 50,\n", " \"pageSize\": num_articles,\n",
" \"sortBy\": \"relevancy\",\n", " \"sortBy\": \"relevancy\",\n",
" \"from\": one_week_ago,\n", " \"from\": from_datetime,\n",
" \"to\": to_datetime,\n",
" },\n", " },\n",
" )\n", " )\n",
"\n", "\n",
@ -217,7 +221,7 @@
" if result[\"status\"] == \"ok\":\n", " if result[\"status\"] == \"ok\":\n",
" articles = articles + result[\"articles\"]\n", " articles = articles + result[\"articles\"]\n",
" else:\n", " else:\n",
" raise Exception(result[\"message\"])" " raise Exception(result[\"message\"])\n"
] ]
}, },
{ {