-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
69 lines (56 loc) · 1.77 KB
/
bot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#-*- coding: utf-8 -*-
import telebot
import authPyDrive as att
from pydrive.drive import GoogleDrive
import os
import time
import tempfile
gauth=att.auth()
bot = telebot.TeleBot( "")
@bot.message_handler(commands=['start', 'help'])
def send_start(msg):
bot.send_message(msg.chat.id , "Bem Vindo !")
@bot.message_handler(content_types=['photo'])
def photo(message):
print('Recebendo Foto')
fileID = message.photo[-1].file_id
file_info = bot.get_file(fileID)
downloaded_file = bot.download_file(file_info.file_path)
f = tempfile.NamedTemporaryFile(mode='wb', delete=False)
f.write(downloaded_file)
file_name = f.name
drive = GoogleDrive(gauth)
file1 = drive.CreateFile({'title': '{}'.format(file_info.file_path)})
file1.SetContentFile(f.name)
file1.Upload()
f.close()
@bot.message_handler(content_types=['video'])
def photo(message):
print('Recebendo Video')
file_info = bot.get_file(message.video.file_id)
downloaded_file = bot.download_file(file_info.file_path)
f = tempfile.NamedTemporaryFile(mode='wb', delete=False)
f.write(downloaded_file)
file_name = f.name
drive = GoogleDrive(gauth)
file1 = drive.CreateFile({'title': '{}'.format(file_info.file_path)})
file1.SetContentFile(f.name)
file1.Upload()
f.close()
@bot.message_handler(content_types=['document'])
def handle_docs_photo(message):
print('Recebendo Documento')
file_info = bot.get_file(message.document.file_id)
print(message.document)
downloaded_file = bot.download_file(file_info.file_path)
src=message.document.file_name
f = tempfile.NamedTemporaryFile(mode='wb', delete=False)
f.write(downloaded_file)
file_name = f.name
drive = GoogleDrive(gauth)
file1 = drive.CreateFile({'title': '{}'.format(src)})
file1.SetContentFile(f.name)
file1.Upload()
f.close()
print("Bot Funcionando !")
bot.polling()