Skip to content

Commit

Permalink
feat: update template
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorentLvr committed Feb 12, 2024
1 parent 2135c4e commit 3f7e8d8
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"tags": []
},
"source": [
"**Tags:** #newsapi #python #api #headlines #news #data"
"**Tags:** #newsapi #python #api #headlines #news #data #command"
]
},
{
Expand Down Expand Up @@ -75,6 +75,7 @@
},
"source": [
"**References:**\n",
"- [Get Your NewsAPI key](https://newsapi.org/register).\n",
"- [News API Documentation](https://newsapi.org/docs/client-libraries/python)\n",
"- [Python Requests Library](https://docs.python-requests.org/en/latest/)"
]
Expand Down Expand Up @@ -125,7 +126,7 @@
"source": [
"### Setup variables\n",
"- `query`: naas.ai, Data & AI platform\n",
"- `api_key`: Your News API key. You can get it from [here](https://newsapi.org/register).\n",
"- `api_key`: Your News API key.\n",
"- `body`: This variable stores the body to be send by the webhook."
]
},
Expand Down Expand Up @@ -222,7 +223,7 @@
" status = \"ok\"\n",
" \n",
" # Manage api key\n",
" if api_key is None:\n",
" if api_key is None or str(api_key) == \"\":\n",
" if naas.secret.get(\"NEWS_API_API_KEY\") is None:\n",
" message = f\"❌ Unable to Connect to News API. Please update your API Key or your query: '{query}'\"\n",
" return status, message\n",
Expand All @@ -234,7 +235,7 @@
" url = f\"https://newsapi.org/v2/top-headlines?q={query}\"\n",
" headers = {\"Authorization\": f\"Bearer {api_key}\"}\n",
" res = requests.get(url, headers=headers)\n",
" if len(res.json()) == 0:\n",
" if len(res.json()) == 0 or len(res.json().get('articles')) == 0:\n",
" message = f\"✅ No articles found.\"\n",
" else:\n",
" message = f\"\"\"\n",
Expand Down

0 comments on commit 3f7e8d8

Please sign in to comment.