mirror of
https://hub.njuu.cf/TheAlgorithms/Python.git
synced 2023-10-11 13:06:12 +08:00
Added a new Python script and some changes in existing one (#1560)
* Python Program that fetches top trending news * Python Program that fetches top trending news * Revisions in Fetch BBC News * psf/black Changes * Python Program to send slack message to a channel * Slack Message Revision Changes
This commit is contained in:
parent
5ac4391420
commit
b7e37a856f
@ -2,7 +2,6 @@
|
||||
|
||||
import requests
|
||||
|
||||
# Enter Your API Key in following URL
|
||||
_NEWS_API = "https://newsapi.org/v1/articles?source=bbc-news&sortBy=top&apiKey="
|
||||
|
||||
|
||||
@ -14,5 +13,5 @@ def fetch_bbc_news(bbc_news_api_key: str) -> None:
|
||||
print(f"{i}.) {article['title']}")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
fetch_bbc_news(bbc_news_api_key="<Your BBC News API key goes here>")
|
||||
|
18
web_programming/slack_message.py
Normal file
18
web_programming/slack_message.py
Normal file
@ -0,0 +1,18 @@
|
||||
# Created by sarathkaul on 12/11/19
|
||||
|
||||
import requests
|
||||
|
||||
|
||||
def send_slack_message(message_body: str, slack_url: str) -> None:
|
||||
headers = {"Content-Type": "application/json"}
|
||||
response = requests.post(slack_url, json={"text": message_body}, headers=headers)
|
||||
if response.status_code != 200:
|
||||
raise ValueError(
|
||||
f"Request to slack returned an error {response.status_code}, "
|
||||
f"the response is:\n{response.text}"
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "main":
|
||||
# Set the slack url to the one provided by Slack when you create the webhook at https://my.slack.com/services/new/incoming-webhook/
|
||||
send_slack_message("<YOUR MESSAGE BODY>", "<SLACK CHANNEL URL>")
|
Loading…
Reference in New Issue
Block a user