Skip to content

Commit eff4102

Browse files
SKAUL05stokhos
authored andcommitted
Added a new Python script and some changes in existing one (TheAlgorithms#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
1 parent 5e4fc44 commit eff4102

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

web_programming/fetch_bbc_news.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import requests
44

5-
# Enter Your API Key in following URL
65
_NEWS_API = "https://newsapi.org/v1/articles?source=bbc-news&sortBy=top&apiKey="
76

87

@@ -14,5 +13,5 @@ def fetch_bbc_news(bbc_news_api_key: str) -> None:
1413
print(f"{i}.) {article['title']}")
1514

1615

17-
if __name__ == '__main__':
16+
if __name__ == "__main__":
1817
fetch_bbc_news(bbc_news_api_key="<Your BBC News API key goes here>")

web_programming/slack_message.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Created by sarathkaul on 12/11/19
2+
3+
import requests
4+
5+
6+
def send_slack_message(message_body: str, slack_url: str) -> None:
7+
headers = {"Content-Type": "application/json"}
8+
response = requests.post(slack_url, json={"text": message_body}, headers=headers)
9+
if response.status_code != 200:
10+
raise ValueError(
11+
f"Request to slack returned an error {response.status_code}, "
12+
f"the response is:\n{response.text}"
13+
)
14+
15+
16+
if __name__ == "main":
17+
# Set the slack url to the one provided by Slack when you create the webhook at https://my.slack.com/services/new/incoming-webhook/
18+
send_slack_message("<YOUR MESSAGE BODY>", "<SLACK CHANNEL URL>")

0 commit comments

Comments
 (0)