@bot.message_handler(commands=['mark'])
def cmd_mark(message):
filed = os.path.getmtime(file)
filef= datetime.fromtimestamp(filed).strftime('%d-%m-%Y %H:%M:%S')
bot.send_message(message.chat.id, 'Последнее изменение файла: {datefile}'.format(datefile=filef))
time.sleep(2) #1
send = bot.send_message(message.chat.id, 'Введи текст')
bot.register_next_step_handler(send, xlsx)
log(message)
def xlsx(message):
bot.send_message(message.chat.id, 'Записано')
time.sleep(3)
date = datetime.now()
quantity = message.text
doc = openpyxl.load_workbook(filename=file)
sheet = doc['test'] #test - название Листа в файле
rows = (
(date, quantity), #date - первая ячейка, quantity вторая ячейка
)
for row in rows:
sheet.append(row)
doc.save(file)
log(message)
@bot.message_handler(content_types={'contact'})
def phone(message):
global sub
sub = [line.rstrip('\n') for line in open(file, 'rt')]
if str(message.text) not in sub:
with open(file, 'a') as f:
f.write(str(message.contact) + "\n")
sub = [line.rstrip('\n') for line in open(file, 'rt')]
print("{0}".format(message.contact))