Skip to main content

Python package for automatically fetching and pushing news by Telegram.

Project description

Telegram-news

PyPI PyPI - Python Version License PyPI - Downloads Codacy Badge

Python package for automatically fetching and pushing news by Telegram.

Simple Start

First of all, install telegram_news:

pip install telegram_news

In a Python file, write:

import os
from sqlalchemy import create_engine
from sqlalchemy.orm import Session

from telegram_news.template.common import InfoExtractor, NewsPostman

# Three required fields:
# Your bot token gotten from @BotFather
bot_token = os.getenv("TOKEN")
# Add your bots into a channel as administrators
channel = os.getenv("CHANNEL")
# Your database to store old messages.
DATABASE_URL = os.getenv("DATABASE_URL")

# Create a database session
engine = create_engine(DATABASE_URL)
db = Session(bind=engine.connect())

# The news source
url = "https://en.wikinews.org/wiki/Main_Page"
tag = "Wiki News"
table_name = "wikinews"

# Info extractor to process data format
ie = InfoExtractor()
ie.set_list_selector('#MainPage_latest_news_text > ul > li')
ie.set_title_selector('#firstHeading')
ie.set_paragraph_selector('#mw-content-text > div > p:not(p:nth-child(1))')
ie.set_time_selector('#mw-content-text > div > p:nth-child(1) > strong')
ie.set_source_selector('span.sourceTemplate')
ie.max_post_length = 2000

# News postman to manage sending affair
np = NewsPostman(listURLs=[url, ], sendList=[channel, ], db=db, tag=tag)
np.set_bot_token(bot_token)
np.set_extractor(ie)
np.set_table_name(table_name)

# Start to work!
np.poll()

Then, you will get messages like this in your channel or group:

Bangladesh reports five new deaths due to COVID-19, a daily highest

Yesterday, Bangladesh has confirmed five new deaths due to COVID-19 on the day. This is the highest number of fatalities in a day due to the virus. As of yesterday, Bangladesh's Institute of Epidemiology, Disease Control and Research (IEDCR) reported the number of recorded infected cases included 114 active cases and 33 recovered cases who were staying home. A total of 17 deaths have been recorded.

In an online news briefing, the director of IEDCR, Dr Meerjady Sabrina Flora

A hospital official told Anadolu Agency, a local news outlet, that one of the deceased was Jalal Saifur Rahman, a director of Bengali Anti-Corruption Commission, who was cared for at the Kuwait Maitree Hospital.

On Saturday, in an online video announcement, Bangladeshi Road Transport and Bridges Minister Obaidul Quader said public transport would be shut down for longer than initially planned, until this coming Saturday. This public transport shutdown had initially started on March 26 and was planned to end on Saturday, April 4. Transport of essential goods -- medical, fuel and food -- was still allowed.

The first recorded incidents of COVID-19 infection in Bangladesh were on March 8, in two people who returned from Italy and also the wife of one of them. As of March 19, these three had already recovered.

Wednesday, April 8, 2020

[ "COVID-19 Confirmed Patients" - IEDCR ] [Full text]

Example

An example channel is @wikinews_en

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

telegram-news-0.2.0.tar.gz (17.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

telegram_news-0.2.0-py3-none-any.whl (16.6 kB view details)

Uploaded Python 3

File details

Details for the file telegram-news-0.2.0.tar.gz.

File metadata

  • Download URL: telegram-news-0.2.0.tar.gz
  • Upload date:
  • Size: 17.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.0

File hashes

Hashes for telegram-news-0.2.0.tar.gz
Algorithm Hash digest
SHA256 55442367d98565a709486ca4cde972910871d5513ac37b3dc867692180cbb764
MD5 cf75125b5d0fcfefb4ef0359621ac52e
BLAKE2b-256 33c5846796f85cce8e84c3d5433f9ab6fb1aded6aa9db0bbc442520e1084bd18

See more details on using hashes here.

File details

Details for the file telegram_news-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: telegram_news-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 16.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.0

File hashes

Hashes for telegram_news-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a2eb94671153796b94b84c92ab7390de9550fbd1cb1cdd6cd449640e0a498ff0
MD5 b640b78cede1917274ea6aa08ee37f26
BLAKE2b-256 ff90a337de576783ac6983afc602163a5ad77a4002e9cf3f4618211cf789ae9b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page