-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
104 lines (80 loc) · 3.66 KB
/
main.py
File metadata and controls
104 lines (80 loc) · 3.66 KB
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
92
93
94
95
96
97
98
99
100
101
102
103
104
import sys
import time
import random
import re
import subprocess
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters
from gtts import gTTS
### UTILITY METHODS ###
def callback_test():
print "Im in"
def ping(bot, update):
bot.sendMessage(update.message.chat_id, text='pong!')
def echo(bot, update):
bot.sendMessage(update.message.chat_id, text=update.message.text)
def testSubprocess():
subprocess.call(['ls', '-1'])
### SEND RANDOM PHOTO ###
def sendImage(bot, update):
url = sendRandomPicture()
bot.sendPhoto(chat_id=update.message.chat_id, photo=url)
### FIND WORD IN A SENTENCE ###
def findWord(bot, update):
# split the sentence from update in words
words_list = update.message.text.split()
# lunch comparision words in list and words split array
for x in words_list:
# if matching call send randon photo
if re.search(r'\b(ascella|Ascella|scella|scelle|Scella|Scelle|Ascelle|ascelle|scell|Scell|ascell|Ascell)\b', x):
index=random.randint(0,4)
if (index % 2) == 0:
sendImage(bot, update)
else:
sendSample(bot, update) #call
def sendRandomPicture():
index = random.randint(0,4)
print index
urls = ['http://www.healcure.org/wp-content/uploads/2015/06/Armpit-hair-image-Girl-with-armpit-hair.jpg','http://qraaunderarm.com/content/images/underarm-slider/underarm1day.png','http://www.healcure.org/wp-content/uploads/2015/05/Underarm-Pain-Causes-Left-Right-Breast-Sharp-Shooting-Pain-under-Armpit.jpg','http://previews.123rf.com/images/ihmb/ihmb0806/ihmb080600483/3191311-Woman-applying-deodorant-on-her-underarm--Stock-Photo-armpit.jpg','http://s.hswstatic.com/gif/eliminate-underarm-odor-1.jpg']
return urls[index]
### GENERATE AUDIO FILE ###
def createAudio(sentence):
tts = gTTS(text=sentence, lang='it')
tts.save('audio_sample2.mp3')
subprocess.call(['./bin/ffmpeg', '-y', '-i', 'audio_sample2.mp3', 'tmp/audio_sample2.ogg'])
return True
def sendAudio(bot, update):
bot.sendVoice(chat_id=update.message.chat_id, voice=open('tmp/audio_sample2.ogg'))
def sendSample(bot, update):
text_to_send = ["I'ch'scell' o frat'", "uua tien'e cozze sotto e' scielle"]
index = random.randint(0,2)
if createAudio(text_to_send[index]) == True:
sendAudio(bot, update)
# def sendAction(bot, update):
# bot.sendChatAction(chat_id=update.message.chat_id, action=telegram.ChatAction.TYPING)
# def sendMessage(bot, update):
# bot.sendMessage(chat_id=update.message.chat_id, text="I'm sorry Dave I'm afraid I can't do that.")
def error(bot, update, error):
logger.warn('Update "%s" caused error "%s"' % (update, error))
TOKEN = ''
def main():
# Create the EventHandler and pass it your bot's token.
updater = Updater(TOKEN)
# Get the dispatcher to register handlers
dp = updater.dispatcher
# on different commands - answer in Telegram
dp.add_handler(CommandHandler("ping", ping))
# dp.add_handler(CommandHandler("help", help))
# on noncommand i.e message - echo the message on Telegram
# dp.add_handler(MessageHandler([Filters.text], echo))
dp.add_handler(MessageHandler([Filters.text], findWord))
# dp.add_handler(RegexHandler('^(ascella|Ascella|scella|scelle|Scella|Scelle|Ascelle|ascelle)$', ashell))
# log all errors
dp.add_error_handler(error)
# Start the Bot
updater.start_polling()
# Run the bot until the you presses Ctrl-C or the process receives SIGINT,
# SIGTERM or SIGABRT. This should be used most of the time, since
# start_polling() is non-blocking and will stop the bot gracefully.
updater.idle()
if __name__ == '__main__':
main()