Как решить?
import telebot
import time
import threading
API_TOKEN = '11111111111111111111111111111111'
class my_bot(telebot.TeleBot):
def loop_poop(self):
while True:
print(time.ctime())
time.sleep(1)
def start_action(self):
thread = threading.Thread(target=self.loop_poop)
thread.start()
bot = my_bot(token = API_TOKEN, threaded=False)
@bot.message_handler(commands=['start'])
def wellcome(message):
if message.chat.type == 'private':
bot.send_message(message.chat.id,'Hello')
bot.start_action()
bot.polling()
@bot.message_handler(content_types=['text']) сделать вычисления, а потом в @bot.callback_query_handler(func=lambda call: True) эти вычисления отправлять.
1 лошадь
5 лошадь
kb2 = types.InlineKeyboardButton('1 horse', callback_data = '1h')
kb3 = types.InlineKeyboardButton('5 horse', callback_data = '10h')
def inline (call): if call.message: if call.data == '10': time.sleep(10)
import telebot
import time
import threading
API_TOKEN = '11111111111111111111111111111111'
class my_bot(telebot.TeleBot):
def loop_poop(self):
while True:
print(time.ctime())
time.sleep(1)
def start_action(self):
thread = threading.Thread(target=self.loop_poop)
thread.start()
bot = my_bot(token = API_TOKEN, threaded=False)
@bot.message_handler(commands=['start'])
def wellcome(message):
if message.chat.type == 'private':
bot.send_message(message.chat.id,'Hello')
bot.start_action()
bot.polling()
from tkinter import *
from time import sleep
class Myfunctions(object):
def __init__(self, window):
self.window = window
def send_email(self):
self.window.title('Sending message..')
sleep(2)
self.window.title('OK')
def send_email_with_error(self):
try:
10/0
except Exception as e:
self.window.title('Error sending: '+ str(e))
window = Tk()
helper = Myfunctions(window)
def on():
helper.send_email()
def off():
helper.send_email_with_error()
on_btn = Button(window,text='on', height=1, width=20, command=lambda:on()).pack()
off_btn = Button(window,text='off', height=1, width=20, command=lambda:off()).pack()
window.geometry('400x50')
window.resizable(width=False, height=False)
window.mainloop()
def count_page(self):
page_count = self.session.get('https://lolz.guru/online/?type=registered&page=1',headers=self.headers)
print(page_count.text)
<!doctype html><html><head><script src="/process-qv9ypsgmv9.js"></script></head><body><script>window.onload=function(){process();}</script><noscript><p>Please enable JavaScript and Cookies in your browser.</p></noscript></body></html>
<a>
, пробовал вручную словить, но так и не удалось. По быстрому будет селениумом. А для парсинга уже класс используй. import requests
from multiprocessing.dummy import Pool as ThreadPool
url = 'https://lolz.guru/online/?type=registered&page='
# Не забудь хедеры и куки прикрутить, а то точно работать не будет
urls = [url+str(i) for i in range(1,8)]# С первой по максимальную страницу
print(urls)
def get_url(url):
r = requests.get(url)
print(r.text)
pool = ThreadPool(20) # Кол-во потоков - по числу ядер, но можно забить и больше, просто работать будет по кол-ву ядер
results = pool.map(get_url, urls)
pool.close()
pool.join()
import json
temp_dict={}
a=["abv","abg","dadad","dsadasd","dsadds"]
b=["agd","dsa","dsad","dsadad","dasdad"]
temp_dict['paler']=a
with open('result.json','w') as json_file:
json.dump(temp_dict,json_file, ensure_ascii=True, indent = 4)
{
"paler": [
"abv",
"abg",
"dadad",
"dsadasd",
"dsadds"
]
}
def draw(self, screen):
rect_image = self.car.get_rect(center=(self.pos[0],self.pos[1]))
screen.blit(self.car, rect_image)
self.draw_radars(screen)
class Users(object):
def __init__(self):
self._users = {}
self.load_users()
def load_users(self):
ffile_info=[]
sfile_info=[]
with open('1.txt','r',encoding='utf-8') as ffile:
ffile_info = ffile.read().splitlines()
with open('2.txt','r',encoding='utf-8') as sfile:
sfile_info = sfile.read().splitlines()
for uinn in ffile_info:
pass
finn = uinn.split(',')[0]
for suinn in sfile_info:
sinn = suinn.split(',')[1][4:]
if finn == sinn:
self._users.update({finn:[uinn.split(',')[1],
uinn.split(',')[2],
suinn.split(',')[0],
suinn.split(',')[2],
suinn.split(',')[3],
suinn.split(',')[4]]})
def check_zp(self):
for user in self._users:
if self._users[user][1] < self._users[user][0]:
print(user, self._users[user][3])
u = Users()
u.check_zp()
from tkinter import *
import time
from threading import *
class My_window(Tk):
def __init__(self):
super(My_window,self).__init__()
self._state = None
self._thread = Thread(target=self.loop_poop)
self._thread.setDaemon(True)
self._thread_active = False
def loop_poop(self):
while self._thread_active:
if self._state:
time.sleep(1)
self.title (time.ctime())
else:
pass
@property
def is_downloading(self):
return self._state
@is_downloading.setter
def is_downloading(self,tpm):
print('Start threding', tpm)
if tpm == True:
if self._thread_active == True:
self._state=True
else:
self._state=True
self._thread_active=True
self._thread.start()
elif tpm == False:
self._state = False
else:
return(False)
def on(window):
window.is_downloading = True
def off(window):
window.is_downloading = False
window = My_window()
on_btn = Button(window,text='on', height=1, width=20, command=lambda window = window:on(window)).pack()
off_btn = Button(window,text='off', height=1, width=20, command=lambda window = window:off(window)).pack()
window.geometry('400x50')
window.resizable(width=False, height=False)
window.mainloop()
from base import Base as db
def connect(db):
......
def download(db):
........
class base:
def __init__( self ):
self.main_database_name=None
.............
@property
def db_name(self):
_db_name = self.main_database_name
return _db_name
def on_select(event, db):
print(db.db_name)
@bot.message_handler(content_types=["video"])
def confirming(message):
if message.content_type == 'video':
print(message.video.file_id) #ID видео файла на сервере
bot.send_video(message.chat.id, message.video.file_id)# Отправляешь его сам себе
else:
pass
@bot.message_handler(commands=['start'])
def start_m(message):
kkb = types.ReplyKeyboardMarkup()
bbt = types.KeyboardButton('Отправить контакт',request_contact=True)
kkb.add(bbt)
bot.send_message(message.chat.id,'Нажми на кнопку, чтобы отправить контакт', reply_markup = kkb)