telegram python news

Solutions on MaxInterview for telegram python news by the best coders in the world

showing results for - "telegram python news"
Ashley
23 Jan 2018
1import os
2from sqlalchemy import create_engine
3from sqlalchemy.orm import Session
4
5from telegram_news.template import InfoExtractor, NewsPostman
6
7# Three required fields:
8# Your bot token gotten from @BotFather
9bot_token = os.getenv("TOKEN")
10# Add your bots into a channel as administrators
11channel = os.getenv("CHANNEL")
12# Your database to store old messages.
13DATABASE_URL = os.getenv("DATABASE_URL")
14
15# Create a database session
16engine = create_engine(DATABASE_URL)
17db = Session(bind=engine.connect())
18
19# The news source
20url = "https://en.wikinews.org/wiki/Main_Page"
21tag = "Wiki News"
22table_name = "wikinews"
23
24# Info extractor to process data format
25ie = InfoExtractor()
26
27# Select select element by CSS-based selector
28ie.set_list_selector('#MainPage_latest_news_text > ul > li')
29ie.set_title_selector('#firstHeading')
30ie.set_paragraph_selector('#mw-content-text > div > p:not(p:nth-child(1))')
31ie.set_time_selector('#mw-content-text > div > p:nth-child(1) > strong')
32ie.set_source_selector('span.sourceTemplate')
33
34# Set a max length for post, Max is 4096
35ie.max_post_length = 2000
36
37# News postman to manage sending affair
38np = NewsPostman(listURLs=[url, ], sendList=[channel, ], db=db, tag=tag)
39np.set_bot_token(bot_token)
40np.set_extractor(ie)
41np.set_table_name(table_name)
42
43# Start to work!
44np.poll()
45