-
Notifications
You must be signed in to change notification settings - Fork 0
/
foobertogram.py
91 lines (81 loc) · 3.5 KB
/
foobertogram.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import time
import random
import datetime
import re
import telepot
import pywapi
from lxml import html
import requests
saludos = ['gay de farmacia', 'gay de circo', 'gay de playa', 'gay de pueblo', 'gay de finca', 'gay de mezquita',
'gay de cantina', 'gay de champa', 'gay asolapado', 'gay de ciudad', 'gay de convento', 'gay de hospital',
'gay de carretera', 'gay de gasolinera']
def handle(msg):
# print(msg)
chat_id = msg['chat']['id']
message = msg['text']
command = message.split(' ', 1)[0]
try:
username = msg['from']['username']
except:
username = msg['from']['first_name']
try:
argumentos = message.split(' ', 1)[1]
except IndexError:
argumentos = ''
# Sanitizando entradas del usuario
argumentos = re.sub('[^A-Za-z]+', '', argumentos)
if command == '/quote':
bot.sendMessage(chat_id, 'Ya casi.... solo faltan un par de detalles')
elif command == '/time':
bot.sendMessage(chat_id, str(datetime.datetime.now()))
elif command == '/fortune':
bot.sendMessage(chat_id, 'No se lo que depara la fortuna')
elif command == '/pipianometro':
bot.sendMessage(chat_id, 'No les hablen de pipianadas que se emocionan...')
elif command == '/urbano':
if argumentos == '':
# Obtener algo random de urbano
page = requests.get('http://www.urbandictionary.com/random.php')
else:
page = requests.get('http://www.urbandictionary.com/define.php?term=' + argumentos)
tree = html.fromstring(page.content)
word = tree.xpath('//a[@class="word"]/text()')
definicion = tree.xpath('//div[@class="meaning"]/text()')
if argumentos == '':
palabra = str(word[0])
content = str(definicion[0])
bot.sendMessage(chat_id, palabra + ' : ' + content)
else:
content = str(definicion[0])
bot.sendMessage(chat_id, argumentos + ' : ' + content)
elif command == '/saludar':
saludo = random.choice(saludos)
if argumentos == '':
bot.sendMessage(chat_id, '@' + username + ' ' + saludo)
else:
bot.sendMessage(chat_id, argumentos + ' ' + saludo)
elif command == '/weather':
if argumentos == '':
bot.sendMessage(chat_id, 'Despues del comando envia la ciudad de la cual quieres saber el clima.')
else:
lookup = pywapi.get_location_ids(argumentos)
test = pywapi.get_location_ids(argumentos)
print(test)
for i in lookup:
location_id = i
weather_com_result = pywapi.get_weather_from_weather_com(location_id, 'C')
condiciones = weather_com_result['current_conditions']['text']
temp = "Weather.com dice que esta " + condiciones.lower() + " y " + \
weather_com_result['current_conditions']['temperature'] + "C ahora en " + \
weather_com_result['location']['name']
bot.sendMessage(chat_id, temp)
elif command == '/help':
bot.sendMessage(chat_id,
'Comandos disponibles?: \n /quote \n /time \n /fortune \n /pipianometro \n /urbano \n /weather')
elif command == '/eshta':
bot.sendMessage(chat_id, '@' + username + ' yo se que te encanta ESHTA, pero trata de controlarte.')
bot = telepot.Bot('317201201:AAHHXyMUVSByqJJO1dBRFT4WGSQ96jjnKm0')
bot.message_loop(handle)
print('Estoy escuchando....')
while 1:
time.sleep(10)