84 lines
3.3 KiB
Python
84 lines
3.3 KiB
Python
import requests
|
|
import telebot
|
|
from bs4 import BeautifulSoup as bs
|
|
from saturn_cli import modulo_scarica
|
|
import csv
|
|
|
|
bot = telebot.TeleBot('5082139972:AAFIcYvf3kjLcm2msTHPODaNuXyIjPFrv9s', parse_mode=None)
|
|
|
|
#########################func per whitelist
|
|
whitelist=["Arcnold_Wp","PlugInSheep",]
|
|
def si_puo(message):
|
|
user=message.from_user.username
|
|
if user in whitelist:
|
|
return True
|
|
else:
|
|
bot.reply_to(message, "Nice try "+str(user))
|
|
return False
|
|
####################
|
|
def send_welcome(message):
|
|
user=message.from_user.username
|
|
if si_puo(message):
|
|
bot.reply_to(message, get_ip())
|
|
@bot.message_handler(commands=['scarica_animu'])
|
|
def animu(message):
|
|
user=message.from_user.username
|
|
if si_puo(message):
|
|
bot.reply_to(message, "Avvio lo scaricamento")
|
|
modulo_scarica()
|
|
bot.reply_to(message, "Ho finito di scaricare")
|
|
############blocco new anime
|
|
@bot.message_handler(commands=['new_animu'])
|
|
def new_animu(message):
|
|
user=message.from_user.username
|
|
if si_puo(message):
|
|
msg=bot.send_message(message.chat.id, """Vuoi inserire un nuovo anime?
|
|
Se si scrivi la cosa da cercare, altrimenti scrivi no""")
|
|
bot.register_next_step_handler(msg, process_scegli_anime)
|
|
def process_scegli_anime(message):
|
|
r=requests.get('https://www.animesaturn.tv/animelist?search='+message.text.strip())
|
|
soup=bs(r.text,'html.parser')
|
|
links=soup.find_all('a',class_='badge badge-archivio badge-light')
|
|
nomi=[nome.text for nome in links]
|
|
risposta=''
|
|
for i in range(len(nomi)):
|
|
risposta=risposta+str(i)+') '+nomi[i]+'\n'
|
|
msg=bot.send_message(message.chat.id,'Quale anime inserisco (inserisci il numero oppure un "no")?\n'+risposta)
|
|
bot.register_next_step_handler(msg,process_link_step,links)
|
|
def process_link_step(message,links):
|
|
if message.text.lower()!="no":
|
|
new_entry=[]
|
|
new_entry.append(links[int(message.text)]['href'])
|
|
print(new_entry)
|
|
msg=bot.send_message(message.chat.id, """In che cartella lo salvo?""")
|
|
bot.register_next_step_handler(msg, process_folder_step, new_entry)
|
|
else:
|
|
bot.send_message(message.chat.id, """Niente allora""")
|
|
def process_folder_step(message, new_entry):
|
|
new_entry.append(message.text.strip())
|
|
print(new_entry)
|
|
msg=bot.send_message(message.chat.id, """Qual'è la stagione di questo anime? Inserisci solo un numero per piacere""")
|
|
bot.register_next_step_handler(msg, process_nome_step, new_entry)
|
|
def process_nome_step(message, new_entry):
|
|
seas_num=format(int(message.text.strip().title()),'02d')
|
|
new_entry.append('Episode S'+seas_num)
|
|
print(new_entry)
|
|
bot.send_message(message.chat.id, str(new_entry))
|
|
msg=bot.send_message(message.chat.id, """Così va bene?(si/NO)""")
|
|
bot.register_next_step_handler(msg, process_verifica_step, new_entry)
|
|
def process_verifica_step(message, new_entry):
|
|
if message.text.lower()=="si":
|
|
with open("animelist.csv",mode='a') as animecsv: #link,cartella,nome,1,1
|
|
csvfile=csv.writer(animecsv)
|
|
new_entry.append("1") #scaricamento attivo
|
|
new_entry.append('1') #new naming convention
|
|
csvfile.writerow(new_entry)
|
|
bot.send_message(message.chat.id, """Anime aggiunto :)""")
|
|
else:
|
|
bot.send_message(message.chat.id, """Niente allora""")
|
|
def smartsearch_anime(ricerca):
|
|
r=requests.get('https://www.animesaturn.in/animelist?search='+ricerca)
|
|
soup=bs(r.text,'html.parser')
|
|
links=soup.find_all('a',class_='badge badge-archivio badge-light')
|
|
bot.infinity_polling(10)
|