A python script that sends me daily top headlines with the help of github actions.
This script creates a telegra.ph page with the news recieved from newsapi.org every time it is executed and sends the link to the telegraph page via telegram bot api.
Here is a link to a sample page that this script creates.
See the logs.txt for latest page created by this script.
- Telegram Bot API
Follow this guide to get a telegram bot api token. - Telegraph API
You can create a telegraph account by using telegraph api python module.
Or you can copy and paste this link with a newshort_name
andauthor_name
in your browser, and copyaccess_token
from there.https://api.telegra.ph/createAccount?short_name=Sandbox&author_name=Anonymous
- NewsAPI.org API Key
Register on newsapi.org to get your api key. - Chat-ID
As this script does not reply to bot commands but rather sends a message automatically, you need to get the chat id for your telegram account for this to work. To get it follow this link.
To access the api keys we need to store them in environment variables. While using github actions to run your scripts these environment variables are called github actions secrets.
To set-up a secret goto, Settings > Secrets > Actions > New repository secret
and save -
- Telegram Bot API key as
TELEGRAM_API_KEY
- Telgraph access token as
TELEGRAPH_TOKEN
- NewsAPI API key as
NEWS_API
- and Chat ID as
CHAT_ID
Now, the script is ready to run.
To change the timing of github actions, edit .github/workflows/main.yml and change - cron * * * * * *
.
To change the localisation and category of news, edit main.py and change top_headlines = newsapi.get_top_headlines(language='en',country='in')
.
Thank You, for visiting my repo.