Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import telebot
- import zipfile
- import os
- import shutil
- import re
- from config import TOKEN
- download_file_path = '/app/files/{}/'
- result_file_path = '/app/files/{}'
- bot = telebot.TeleBot(TOKEN)
- @bot.message_handler(commands=['start'])
- def start_message(message):
- bot.send_message(message.chat.id, 'Choose operation')
- @bot.message_handler(content_types=['document'])
- def handle_file_message(message):
- file_info = bot.get_file(message.document.file_id)
- downloaded_file = bot.download_file(file_info.file_path)
- if re.search('.zip', message.document.file_name):
- src= download_file_path.format('to_extract')+message.document.file_name
- else:
- src= download_file_path.format('to_compress')+message.document.file_name
- print(src)
- with open(src, 'wb') as new_file:
- new_file.write(downloaded_file)
- if zipfile.is_zipfile(src):
- z = zipfile.ZipFile(src, 'r')
- res = result_file_path + message.document.file_name.format('extracted/')
- z.extractall(res)
- z.close()
- for file in os.listdir(res):
- if file != '.gitkeep':
- bot.send_document(message.chat.id, open(os.path.join(res,file), 'rb'))
- os.remove(src)
- shutil.rmtree(res)
- else:
- bot.send_message(message.chat.id, 'File to compress was upload.')
- @bot.message_handler(commands=['compress'])
- @bot.message_handler(content_types=['document'])
- def handle_file_message(message):
- res = '/app/files/compress/archive.zip'
- fol = download_file_path.format('to_compress')
- new_zip = zipfile.ZipFile(result_file_path.format('compress/archive.zip'), 'w')
- if os.listdir(fol):
- for file in os.listdir(fol):
- if file != '.gitkeep':
- new_zip.write(os.path.join(fol,file), arcname=file)
- new_zip.close()
- bot.send_document(message.chat.id, open(os.path.join('/app/files',res), 'rb'))
- os.remove(res)
- for file in os.listdir(fol):
- if file != '.gitkeep':
- os.remove(os.path.join(fol,file))
- else:
- bot.send_message(message.chat.id, 'No files to compress.')
- bot.polling()
- 2019-06-02T18:01:13.354064+00:00 app[api]: Starting process with command `bash` by user exs2199@gmail.com
- 2019-06-02T18:01:17.308413+00:00 heroku[run.1550]: State changed from starting to up
- 2019-06-02T18:01:17.283624+00:00 heroku[run.1550]: Awaiting client
- 2019-06-02T18:01:17.634251+00:00 heroku[run.1550]: Starting process with command `bash`
- 2019-06-02T18:01:45.544024+00:00 heroku[web.1]: State changed from starting to crashed
- 2019-06-02T18:01:45.420972+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
- 2019-06-02T18:01:45.421178+00:00 heroku[web.1]: Stopping process with SIGKILL
- 2019-06-02T18:01:45.516597+00:00 heroku[web.1]: Process exited with status 137
- 2019-06-02T18:02:19.897005+00:00 heroku[run.1550]: Client connection closed. Sending SIGHUP to all processes
- 2019-06-02T18:02:20.445889+00:00 heroku[run.1550]: State changed from up to complete
- 2019-06-02T18:02:20.425364+00:00 heroku[run.1550]: Process exited with status 129
- 2019-06-02T18:02:24.991830+00:00 heroku[web.1]: State changed from crashed to starting
- 2019-06-02T18:02:28.893925+00:00 heroku[web.1]: Starting process with command `python3 /app/tbot/z.py`
- 2019-06-02T18:02:32.216906+00:00 app[web.1]: /app/files/to_compress/1.txt
- 2019-06-02T18:03:29.213961+00:00 heroku[web.1]: State changed from starting to crashed
- 2019-06-02T18:03:29.078950+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
- 2019-06-02T18:03:29.078950+00:00 heroku[web.1]: Stopping process with SIGKILL
- 2019-06-02T18:03:29.189754+00:00 heroku[web.1]: Process exited with status 137
- 2019-06-02T18:10:19.362884+00:00 heroku[web.1]: State changed from crashed to starting
- 2019-06-02T18:10:22.485092+00:00 heroku[web.1]: Starting process with command `python3 /app/tbot/z.py`
- 2019-06-02T18:11:22.947812+00:00 heroku[web.1]: State changed from starting to crashed
- 2019-06-02T18:11:22.821322+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
- 2019-06-02T18:11:22.821465+00:00 heroku[web.1]: Stopping process with SIGKILL
- 2019-06-02T18:11:22.928462+00:00 heroku[web.1]: Process exited with status 137
- 2019-06-02T18:39:11.058896+00:00 heroku[web.1]: State changed from crashed to starting
- 2019-06-02T18:39:14.258197+00:00 heroku[web.1]: Starting process with command `python3 /app/tbot/z.py`
- 2019-06-02T18:40:14.880591+00:00 heroku[web.1]: State changed from starting to crashed
- 2019-06-02T18:40:14.783011+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
- 2019-06-02T18:40:14.783011+00:00 heroku[web.1]: Stopping process with SIGKILL
- 2019-06-02T18:40:14.858099+00:00 heroku[web.1]: Process exited with status 137
- 2019-06-02T18:45:02.456324+00:00 heroku[web.1]: State changed from crashed to starting
- 2019-06-02T18:45:05.327801+00:00 heroku[web.1]: Starting process with command `python3 /app/tbot/z.py`
- 2019-06-02T18:45:07.558714+00:00 app[web.1]: /app/files/to_compress/1.txt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement