Advertisement
Guest User

Untitled

a guest
Jun 15th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.11 KB | None | 0 0
  1. import telebot
  2. import zipfile
  3. import os
  4. import shutil
  5. import re
  6.  
  7. from config import TOKEN
  8.  
  9. download_file_path = '/app/files/{}/'
  10. result_file_path = '/app/files/{}'
  11.  
  12. bot = telebot.TeleBot(TOKEN)
  13.  
  14.  
  15. @bot.message_handler(commands=['start'])
  16. def start_message(message):
  17. bot.send_message(message.chat.id, 'Choose operation')
  18.  
  19. @bot.message_handler(content_types=['document'])
  20. def handle_file_message(message):
  21. file_info = bot.get_file(message.document.file_id)
  22. downloaded_file = bot.download_file(file_info.file_path)
  23. if re.search('.zip', message.document.file_name):
  24. src= download_file_path.format('to_extract')+message.document.file_name
  25. else:
  26. src= download_file_path.format('to_compress')+message.document.file_name
  27. print(src)
  28. with open(src, 'wb') as new_file:
  29. new_file.write(downloaded_file)
  30. if zipfile.is_zipfile(src):
  31. z = zipfile.ZipFile(src, 'r')
  32. res = result_file_path + message.document.file_name.format('extracted/')
  33. z.extractall(res)
  34. z.close()
  35. for file in os.listdir(res):
  36. if file != '.gitkeep':
  37. bot.send_document(message.chat.id, open(os.path.join(res,file), 'rb'))
  38. os.remove(src)
  39. shutil.rmtree(res)
  40. else:
  41. bot.send_message(message.chat.id, 'File to compress was upload.')
  42.  
  43. @bot.message_handler(commands=['compress'])
  44. @bot.message_handler(content_types=['document'])
  45. def handle_file_message(message):
  46. res = '/app/files/compress/archive.zip'
  47. fol = download_file_path.format('to_compress')
  48. new_zip = zipfile.ZipFile(result_file_path.format('compress/archive.zip'), 'w')
  49. if os.listdir(fol):
  50. for file in os.listdir(fol):
  51. if file != '.gitkeep':
  52. new_zip.write(os.path.join(fol,file), arcname=file)
  53. new_zip.close()
  54. bot.send_document(message.chat.id, open(os.path.join('/app/files',res), 'rb'))
  55. os.remove(res)
  56. for file in os.listdir(fol):
  57. if file != '.gitkeep':
  58. os.remove(os.path.join(fol,file))
  59. else:
  60. bot.send_message(message.chat.id, 'No files to compress.')
  61. bot.polling()
  62.  
  63. 2019-06-02T18:01:13.354064+00:00 app[api]: Starting process with command `bash` by user exs2199@gmail.com
  64. 2019-06-02T18:01:17.308413+00:00 heroku[run.1550]: State changed from starting to up
  65. 2019-06-02T18:01:17.283624+00:00 heroku[run.1550]: Awaiting client
  66. 2019-06-02T18:01:17.634251+00:00 heroku[run.1550]: Starting process with command `bash`
  67. 2019-06-02T18:01:45.544024+00:00 heroku[web.1]: State changed from starting to crashed
  68. 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
  69. 2019-06-02T18:01:45.421178+00:00 heroku[web.1]: Stopping process with SIGKILL
  70. 2019-06-02T18:01:45.516597+00:00 heroku[web.1]: Process exited with status 137
  71. 2019-06-02T18:02:19.897005+00:00 heroku[run.1550]: Client connection closed. Sending SIGHUP to all processes
  72. 2019-06-02T18:02:20.445889+00:00 heroku[run.1550]: State changed from up to complete
  73. 2019-06-02T18:02:20.425364+00:00 heroku[run.1550]: Process exited with status 129
  74. 2019-06-02T18:02:24.991830+00:00 heroku[web.1]: State changed from crashed to starting
  75. 2019-06-02T18:02:28.893925+00:00 heroku[web.1]: Starting process with command `python3 /app/tbot/z.py`
  76. 2019-06-02T18:02:32.216906+00:00 app[web.1]: /app/files/to_compress/1.txt
  77. 2019-06-02T18:03:29.213961+00:00 heroku[web.1]: State changed from starting to crashed
  78. 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
  79. 2019-06-02T18:03:29.078950+00:00 heroku[web.1]: Stopping process with SIGKILL
  80. 2019-06-02T18:03:29.189754+00:00 heroku[web.1]: Process exited with status 137
  81. 2019-06-02T18:10:19.362884+00:00 heroku[web.1]: State changed from crashed to starting
  82. 2019-06-02T18:10:22.485092+00:00 heroku[web.1]: Starting process with command `python3 /app/tbot/z.py`
  83. 2019-06-02T18:11:22.947812+00:00 heroku[web.1]: State changed from starting to crashed
  84. 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
  85. 2019-06-02T18:11:22.821465+00:00 heroku[web.1]: Stopping process with SIGKILL
  86. 2019-06-02T18:11:22.928462+00:00 heroku[web.1]: Process exited with status 137
  87. 2019-06-02T18:39:11.058896+00:00 heroku[web.1]: State changed from crashed to starting
  88. 2019-06-02T18:39:14.258197+00:00 heroku[web.1]: Starting process with command `python3 /app/tbot/z.py`
  89. 2019-06-02T18:40:14.880591+00:00 heroku[web.1]: State changed from starting to crashed
  90. 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
  91. 2019-06-02T18:40:14.783011+00:00 heroku[web.1]: Stopping process with SIGKILL
  92. 2019-06-02T18:40:14.858099+00:00 heroku[web.1]: Process exited with status 137
  93. 2019-06-02T18:45:02.456324+00:00 heroku[web.1]: State changed from crashed to starting
  94. 2019-06-02T18:45:05.327801+00:00 heroku[web.1]: Starting process with command `python3 /app/tbot/z.py`
  95. 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