|
1 | 1 | from django.core.management.base import BaseCommand, CommandError
|
2 |
| -from medios_libres.models import Texto, Ubicacion |
3 |
| -import telebot |
4 |
| -from telebot import types |
5 |
| - |
6 |
| -# token medios libres |
7 |
| -token = "317988596:AAEH2w1RxDYg26hf0aVVFuqtscM7d8dr98Q" |
| 2 | +from medios_libres.models import MediosBot |
8 | 3 |
|
9 | 4 | class Command(BaseCommand):
|
10 |
| - help = 'Listen to Telegram Bot in the background' |
| 5 | + help = """Listen to Telegram Bot in the background |
| 6 | + (medios_venv)$ python manage.py bot_listen""" |
11 | 7 |
|
12 | 8 | def handle(self, *args, **options):
|
13 |
| - bot = telebot.TeleBot(token) |
14 |
| - |
15 |
| - geo = types.ReplyKeyboardMarkup(row_width=1, resize_keyboard=True) |
16 |
| - boton = types.KeyboardButton('Enviar posicion', request_location=True) |
17 |
| - geo.add(boton) |
18 |
| - |
19 |
| - @bot.message_handler(commands=['monitor',]) |
20 |
| - def mandar_posicion(message): |
21 |
| - """al comando /monitor responde con un teclado con el boton para enviar ubicacion""" |
22 |
| - cid = message.chat.id |
23 |
| - bot.send_message(cid, "Reportar mi ubicacion", reply_markup=geo) |
24 |
| - |
25 |
| - @bot.message_handler(content_types=['location',]) |
26 |
| - def recibir_posicion(message): |
27 |
| - user=message.from_user |
28 |
| - if user.username: |
29 |
| - username = user.username |
30 |
| - elif user.first_name: |
31 |
| - username = user.first_name |
32 |
| - elif user.last_name: |
33 |
| - username = user.last_name |
34 |
| - latitude = message.location.latitude |
35 |
| - longitude = message.location.longitude |
36 |
| - try: |
37 |
| - Ubicacion.objects.create(lat=latitude, longi=longitude, usuario=username) |
38 |
| - except Exception: |
39 |
| - print("falla lat:{}, long:{}, user:{}".format(latitude, longitude, username)) |
40 |
| - # TODO FWD |
41 |
| - |
42 |
| - bot.polling() |
| 9 | + medios = MediosBot() |
| 10 | + medios.bot.polling() |
0 commit comments