Aggiornare 'lordchannel.py'

master
MickSlash 2020-06-06 13:53:34 +00:00
parent 5e72a51efa
commit cfbe4a1f1c
1 changed files with 54 additions and 9 deletions

View File

@ -1,24 +1,69 @@
import telebot
import bs4, requests
import time
API_TOKEN = '1131828244:AAGdoGSg2wNnqpJxSOwTzeD94TYQKT1C-xM'
url = "https://lordchannel.com/"
bot = telebot.TeleBot(API_TOKEN)
def getLC(url):
res = requests.get(url)
res.raise_for_status()
soup = bs4.BeautifulSoup(res.text,"html.parser")
elementi = soup.select('#post-123 > div > div > div.fl-row.fl-row-fixed-width.fl-row-bg-photo.fl-node-5bab8763f0554.fl-row-bg-overlay > div > div > div > div > div > div > div > div > div > ul')
elems = soup.select('#post-123 > div > div > div.fl-row.fl-row-fixed-width.fl-row-bg-photo.fl-node-5bab8763f0554.fl-row-bg-overlay > div > div > div > div > div > div > div > div > div > ul > li:nth-child(6) > a')
links_with_text = []
for a in soup.find_all('a', href=True):
if a.text:
links_with_text.append(a['href'])
return elems[0].text.strip(),elementi[0].text.strip()
# articoli = "\n"
elementi = soup.select('#post-123 > div > div > div.fl-row.fl-row-fixed-width.fl-row-bg-photo.fl-node-5bab8763f0554.fl-row-bg-overlay > div > div > div > div > div > div > div > div > div > ul')
elem = elementi[0].find_all('a',href=True)
for a in elem:
if a.text:
links_with_text.append(a['href'])
articolo_1 = links_with_text[0]
articolo_2 = links_with_text[1]
articolo_3 = links_with_text[2]
articolo_4 = links_with_text[3]
articolo_5 = links_with_text[4]
articolo_6 = links_with_text[5]
# articoli = articoli.join(links_with_text)
# articoli = articoli.join(elementi[0].text.strip())
return articolo_1,articolo_2,articolo_3,articolo_4,articolo_5,articolo_6
articolo_1,articolo_2,articolo_3,articolo_4,articolo_5,articolo_6 = getLC(url)
# Handle '/start' and '/help'
@bot.message_handler(commands=['help', 'start'])
def send_welcome(message):
name = message.from_user.first_name
bot.reply_to(message, f"""\
Ciao {name} , tramite questo bot verrai informato sugli ultimi articoli pubblicati su LORDCHANNEL.
Che cosa aspetti? Inizia subito!\
""")
elemento,articoli = getLC(url)
# Handle '/articoli'
@bot.message_handler(commands=['articoli'])
def ultimi_articoli(message):
articoli = getLC(url)
name = message.from_user.first_name
bot.reply_to(message, f"""\
Ciao {name} , gli ultimi articoli caricati su LORDCHANNEL sono :\
""")
bot.reply_to(message,f"{articolo_1}")
time.sleep(2)
bot.reply_to(message,f"{articolo_2}")
time.sleep(2)
bot.reply_to(message,f"{articolo_3}")
time.sleep(2)
bot.reply_to(message,f"{articolo_4}")
time.sleep(2)
bot.reply_to(message,f"{articolo_5}")
time.sleep(2)
bot.reply_to(message,f"{articolo_6}")
time.sleep(2)
print(f"{articoli}")
# print(f"{elemento}")
bot.polling()
# # print(f"{elemento}")