Skip to content

Added a new Python script and some changes in existing one #1560

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Nov 12, 2019
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions web_programming/fetch_bbc_news.py
Original file line number Diff line number Diff line change
Expand Up @@ -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="


Expand All @@ -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>")
20 changes: 20 additions & 0 deletions web_programming/slack_message.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Created by sarathkaul on 12/11/19

import json
import requests


def send_slack_message(message_body, slack_url):
slack_data = {"text": message_body}
headers = {"Content-Type": "application/json"}
response = requests.post(slack_url, data=json.dumps(slack_data), headers=headers)
if response.status_code != 200:
raise ValueError(
"Request to slack returned an error %s, the response is:\n%s"
% (response.status_code, 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>")