From c3778e6c1b1339804dc19fc3a928aecbf4f25055 Mon Sep 17 00:00:00 2001 From: aleksei1988 Date: Sun, 25 Dec 2022 20:39:52 +0200 Subject: [PATCH] Done --- .gitignore | 1 + Dockerfile | 6 +++--- app.py | 19 ++++++++++++++----- utils.py | 2 +- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index bf0d076..8cbcc87 100644 --- a/.gitignore +++ b/.gitignore @@ -154,3 +154,4 @@ crashlytics.properties crashlytics-build.properties fabric.properties +/.telegramToken diff --git a/Dockerfile b/Dockerfile index ac0a3bb..fc3f85b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ FROM python:3.8.12-slim-buster -# YOUR COMMANDS HERE -# .... -# .... +WORKDIR /TelegramAI +COPY . . +RUN pip install -r requirements.txt CMD ["python3", "app.py"] \ No newline at end of file diff --git a/app.py b/app.py index 45e12d7..b73a40c 100644 --- a/app.py +++ b/app.py @@ -46,6 +46,10 @@ def download_user_photo(self, quality=0): file_info = self.bot.get_file(self.current_msg.photo[quality].file_id) data = self.bot.download_file(file_info.file_path) + with open(file_info.file_path, 'wb') as photo: + photo.write(data) + + return file_info # TODO save `data` as a photo in `file_info.file_path` path def handle_message(self, message): @@ -61,14 +65,19 @@ def handle_message(self, message): class YoutubeBot(Bot): - pass - + def handle_message(self, video_name): + if self.current_msg.content_type == 'photo': + self.download_user_photo() + else: + logger.info(f'Insert Video Name: {video_name}') + result = search_download_youtube_video(video_name.text) + url = result[0]['url'] + self.send_text(f'Video Link: {url}') if __name__ == '__main__': with open('.telegramToken') as f: _token = f.read() my_bot = Bot(_token) - my_bot.start() - - + my_bot = YoutubeBot(_token) + my_bot.start() \ No newline at end of file diff --git a/utils.py b/utils.py index e5426e0..8c4411f 100644 --- a/utils.py +++ b/utils.py @@ -21,4 +21,4 @@ def search_download_youtube_video(video_name, num_results=1): 'url': video['webpage_url'] }) - return results + return results \ No newline at end of file