def __init__(self, parent=None): """ Constructor @param parent reference to the parent widget (QWidget) """ self.server_model = ServerModel() self.platform_model = PlatformModel() self.solution_model = SolutionModel() self.upload_thread = UploadThread() self.upload_thread.finished.connect(self.on_upload_thread_finished) self.upload_thread.information.connect( self.on_upload_thread_information) super(MainWindow, self).__init__(parent) self.setupUi(self) self.initUi() self.initData() self.createContextMenu()
def echo(): global LAST_UPDATE_ID # Request updates from last updated_id for update in bot.getUpdates(offset=LAST_UPDATE_ID): if LAST_UPDATE_ID < update.update_id: # chat_id is required to reply any message chat_id = update.message.chat_id message = update.message.text if (message): if '/start' in message or '/help' in message or '/list' in message or '/commands' in message: bot.sendChatAction(chat_id=chat_id, action=telegram.ChatAction.TYPING) bot.sendMessage(chat_id=chat_id, text=help.encode('utf8'), disable_web_page_preview=True) ##################----- PublicPlugins -----################## #Require API keys '''Youtube search''' if '/yt' in message or '/youtube' in message: bot.sendChatAction(chat_id=chat_id, action=telegram.ChatAction.TYPING) replacer = {'/youtube': '', '/yt': ''} search_term = replace_all(message, replacer) if len(search_term) < 1: bot.sendMessage( chat_id=chat_id, text= 'Youtube API calls are costly. Use it like /yt keywords; Ex, /yt Iron Maiden' ) else: bot.sendMessage( chat_id=chat_id, text=youtube(search_term).encode('utf8')) '''Twitter latest tweets of user''' if '/twitter' in message or '/tw' in message: bot.sendChatAction(chat_id=chat_id, action=telegram.ChatAction.TYPING) replacer = {'/twitter': '', '/tw': ''} username = replace_all(message, replacer) if len(username) < 1: bot.sendMessage( chat_id=chat_id, text='Use it like: /tw username; Ex, /tw pytacular' ) else: bot.sendMessage(chat_id=chat_id, text=twitter(username).encode('utf8')) '''Gets twitter trends by country /tt countryname, ex /tt India ''' if '/tt' in message: bot.sendChatAction(chat_id=chat_id, action=telegram.ChatAction.TYPING) replacer = {'/tt ': ''} place = replace_all(message, replacer) bot.sendMessage(chat_id=chat_id, text=twittertrends(place).encode('utf8')) '''Search twitter for top 4 related tweets. /ts #Privacy''' if '/ts' in message: bot.sendChatAction(chat_id=chat_id, action=telegram.ChatAction.TYPING) replacer = {'/ts ': ''} search_term = replace_all(message, replacer) bot.sendMessage( chat_id=chat_id, text=twittersearch(search_term).encode('utf8')) '''Instagram latest posts of user''' if '/insta' in message or '/instagram' in message: bot.sendChatAction(chat_id=chat_id, action=telegram.ChatAction.TYPING) bot.sendMessage( chat_id=chat_id, text= 'Instagram has restricted API access. This will not work anymore. Sorry :(' ) '''Game "Hot or Not" ''' if '/hon' in message or '/hotornot' in message: bot.sendChatAction(chat_id=chat_id, action=telegram.ChatAction.TYPING) custom_keyboard = [[ telegram.Emoji.THUMBS_UP_SIGN, telegram.Emoji.THUMBS_DOWN_SIGN ]] reply_markup = telegram.ReplyKeyboardMarkup( custom_keyboard, resize_keyboard=True, one_time_keyboard=True) image = imgur_hon() bot.sendMessage( chat_id=chat_id, text='Fetched from Imgur Subreddit r/models : ' + image, reply_markup=reply_markup) '''Bing Image Search''' if '/image' in message or '/img' in message: bot.sendChatAction(chat_id=chat_id, action=telegram.ChatAction.TYPING) replacer = {'/image': '', '/img': ''} search_term = replace_all(message, replacer) pic_link = bingsearch(search_term, 'Image') bot.sendMessage(chat_id=chat_id, text=pic_link) '''Microsoft translator''' if '/translate' in message: message = message.replace('/translate', '').encode('utf8') message_broken = shlex.split(message) error = 'Not enough parameters. Use, /translate en hi "Hello world" or /translate help to know more' if not len(message_broken) < 1: if message_broken[0] == 'help': help_string = """ Example, /translate en hi "Hello world" ar-Arabic | bs-Latn-Bosnian (Latin) | bg-Bulgarian | ca-Catalan | zh-CHS-Chinese Simplified | zh-CHT-Chinese Traditional|hr-Croatian | cs-Czech | da-Danish | nl-Dutch |en-English | cy-Welsh | et-Estonian | fi-Finnish | fr-French | de-German | el-Greek | ht-Haitian Creole | he-Hebrew | hi-Hindi | mww-Hmong Daw | hu-Hungarian | id-Indonesian | it-Italian | ja-Japanese | tlh-Klingon | tlh - Qaak-Klingon (pIqaD) | ko-Korean | lv-Latvian | lt-Lithuanian | ms-Malay | mt-Maltese | no-Norwegian | fa-Persian | pl-Polish | pt-Portuguese | otq-Querétaro Otomi | ro-Romanian | ru-Russian | sr-Cyrl-Serbian (Cyrillic) | sr-Latn-Serbian (Latin) | sk-Slovak | sl-Slovenian | es-Spanish | sv-Swedish | th-Thai | tr-Turkish | uk-Ukrainian | ur-Urdu | vi-Vietnamese | """ bot.sendMessage(chat_id=chat_id, text=help_string) else: if len(message_broken) < 3: bot.sendMessage(chat_id=chat_id, text=error) else: lang_from = message_broken[0] lang_to = message_broken[1] lang_text = message_broken[2] print(lang_from + lang_to + lang_text) bot.sendMessage(chat_id=chat_id, text=btranslate( lang_text, lang_from, lang_to)) else: bot.sendMessage(chat_id=chat_id, text=error) '''Random cat pic''' if '/cats' in message: bot.sendMessage( chat_id=chat_id, text='Hold on, digging out a random cat pic!') url = "http://thecatapi.com/api/images/get?api_key=" + cat_API_key + "&format=xml" xml_src = urllib.request.urlopen(url) data = xml_src.read() xml_src.close() data = xmltodict.parse(data) piclink = data['response']['data']['images']['image'][ 'url'] source_url = data['response']['data']['images']['image'][ 'source_url'] threadobjcats = UploadThread(bot, chat_id, piclink, caption=source_url) threadobjcats.setName('catsthread') threadobjcats.start() # Don't need an API key '''Google search''' if '/google' in message: bot.sendChatAction(chat_id=chat_id, action=telegram.ChatAction.TYPING) search_term = message.replace('/google', '') if len(search_term) < 1: bot.sendMessage( chat_id=chat_id, text='Use it like: /google what is a bot') else: bot.sendMessage(chat_id=chat_id, text=google(search_term)) '''Wikipedia search''' if '/wiki' in message: bot.sendChatAction(chat_id=chat_id, action=telegram.ChatAction.TYPING) search_term = message.replace('/wiki ', '') if len(search_term) < 1: bot.sendMessage(chat_id=chat_id, text='Use it like: /wiki Anaconda') else: reply = wiki(search_term) bot.sendMessage(chat_id=chat_id, text=reply) if ("Cannot acces link!" in reply): reply = "No wikipedia article on that but got some google results for you \n" + google( message) bot.sendMessage(chat_id=chat_id, text=reply) '''Weather by city,state''' if '/weather' in message: bot.sendChatAction(chat_id=chat_id, action=telegram.ChatAction.TYPING) reply = weather(message) bot.sendMessage(chat_id=chat_id, text=reply) '''Github public feed of any user''' if '/github' in message or '/gh' in message: bot.sendChatAction(chat_id=chat_id, action=telegram.ChatAction.TYPING) replacer = {'/github': '', '/gh': ''} username = replace_all(message, replacer) if len(username) < 1: bot.sendMessage( chat_id=chat_id, text= 'Use it like: /github username Ex, /github bhavyanshu or /gh bhavyanshu' ) else: bot.sendMessage(chat_id=chat_id, text=gitfeed(username)) '''Giphy to search for gif by keyword''' if '/giphy' in message or '/gif' in message: bot.sendChatAction(chat_id=chat_id, action=telegram.ChatAction.TYPING) replacer = {'/giphy': '', '/gif': ''} search_term = replace_all(message, replacer) if len(search_term) < 1: bot.sendMessage( chat_id=chat_id, text= 'Use it like: /giphy keyword ; Ex, /giphy cats or /gif cats' ) else: img = translate(search_term) print(img.fixed_height.downsampled.url) bot.sendMessage( chat_id=chat_id, text= 'Hang in there. Fetching gif..-Powered by GIPHY!') bot.sendChatAction( chat_id=chat_id, action=telegram.ChatAction.UPLOAD_PHOTO) threadobjgiphy = UploadThread( bot, chat_id, img.fixed_height.downsampled.url.encode('utf-8')) threadobjgiphy.setName('giphythread') threadobjgiphy.start() '''Basic calculator''' if '/calc' in message: head, sep, tail = message.partition('/') input_nums = tail.replace('calc', '') input_nums = input_nums.replace('\'', '') finalexp = shlex.split(input_nums) exp = finalexp[0] bot.sendChatAction(chat_id=chat_id, action=telegram.ChatAction.TYPING) error = 'You think I can compute apple+mongo? Don\'t add alphabet in between please. Use like, /calc 2+2-5(4+8)' if not exp: bot.sendMessage( chat_id=chat_id, text='Y u no type math expression? >.<') elif re.search('[a-zA-Z]', exp): bot.sendMessage(chat_id=chat_id, text=error) else: bot.sendMessage(chat_id=chat_id, text=calculate(exp)) # Updates global offset to get the new updates LAST_UPDATE_ID = update.update_id