def command( message, user, channel ): try: res = requests.get( "http://www.google.com/search?q=" + message ) # There is a lot of shit. Cut off as much as possible before sending it to the HTML parser in an effort to speed up parsing datlongtext = __main__.strbetween( res.text, " id=\"resultStats\">", "</html>" ) datlongtext = datlongtext.replace( "<b>", "" ).replace( "</b>", "" ).replace( "<em>", "" ).replace( "</em>", "" ) # Get rid of bolds, this tends to be used just to highlight the keyword searched resultOneUnparsed = __main__.strbetween( datlongtext, "<h3 class=\"r\">", "</h3>" ) # The link and result text come between this datlongtext = datlongtext.replace( "<h3 class=\"r\">" + resultOneUnparsed + "</h3>", "" ) # Now that we got the first one, get rid of it to find the next one resultTwoUnparsed = __main__.strbetween( datlongtext, "<h3 class=\"r\">", "</h3>" ) datlongtext = datlongtext.replace( "<h3 class=\"r\">" + resultTwoUnparsed + "</h3>", "" ) resultThreeUnparsed = __main__.strbetween( datlongtext, "<h3 class=\"r\">", "</h3>" ) datlongtext = datlongtext.replace( "<h3 class=\"r\">" + resultThreeUnparsed + "</h3>", "" ) # Great, now we've got the three results isolated. Let's parse them! resultOneLink = __main__.strbetween( resultOneUnparsed, "<a href=\"/url?q=", "&sa=U" ) resultTwoLink = __main__.strbetween( resultTwoUnparsed, "<a href=\"/url?q=", "&sa=U" ) resultThreeLink = __main__.strbetween( resultThreeUnparsed, "<a href=\"/url?q=", "&sa=U" ) resultOneText = __main__.strbetween( resultOneUnparsed, "\">", "</a>" ) resultTwoText = __main__.strbetween( resultTwoUnparsed, "\">", "</a>" ) resultThreeText = __main__.strbetween( resultThreeUnparsed, "\">", "</a>" ) if resultOneLink != "" and resultOneText != "": __main__.sendMessage( htmlCleaner( resultOneText ) + " - " + htmlCleaner( resultOneLink ), channel ) if resultTwoLink != "" and resultTwoText != "": threading.Timer( 0.5, __main__.sendMessage, args=( htmlCleaner( resultTwoText ) + " - " + htmlCleaner( resultTwoLink ), channel ) ).start() if resultThreeLink != "" and resultThreeText != "": threading.Timer( 1.0, __main__.sendMessage, args=( htmlCleaner( resultThreeText ) + " - " + htmlCleaner( resultThreeLink ), channel ) ).start() return True except: return False
def command( message, user, channel ): try: res = requests.get( "http://qdb.us/random/" ) quoteNum = __main__.fixHTMLCharsAdvanced( __main__.strbetween( res.text, "\">#", "</a>" ) ) quote = __main__.fixHTMLCharsAdvanced( __main__.strbetween( res.text, "<span class=qt id=qt" + quoteNum , "</span>" ) ) quote = quote.replace( "<br />", " / " ) __main__.sendMessage( "Quote #" + quoteNum + ": " + quote, channel ) return True except: return False
def command( message, user, channel ): try: res = requests.get( "http://whatthefuckshouldimakefordinner.com/" ) meal = __main__.fixHTMLChars( __main__.strbetween( res.text, "\" target=\"_blank\">", "</a></dt>" ) ) url = __main__.fixHTMLChars( __main__.strbetween( res.text, "<dt><a href=\"", "\" target=\"_blank\">" ) ) if meal != "": __main__.sendMessage( meal + " - " + url, channel ) else: __main__.sendMessage( "You will starve!", channel ) return True except: return False
def command( message, user, channel ): try: res = requests.get( "https://live.xbox.com/en-US/Profile?gamertag=" + message ) gamerscore = __main__.fixHTMLChars( __main__.strbetween( res.text, "<div class=\"gamerscore\">", "</div>" ) ) lastseen = __main__.fixHTMLChars( __main__.strbetween( res.text, "<div class=\"presence\">", "</div>" ) ) gamertag = __main__.fixHTMLChars( __main__.strbetween( res.text, "<title>", "'s Profile" ) ) #get proper case of gamertag if gamerscore != "": __main__.sendMessage( gamertag + " :: Status: " + lastseen + " :: Gamerscore: " + gamerscore, channel ) else: __main__.sendMessage( message + " was not found.", channel ) return True except: return False
def command( message, user, channel ): try: res = requests.get( "http://www.randomriddles.com/" ) riddle = __main__.fixHTMLCharsAdvanced( __main__.strbetween( res.text, "<strong><i>", " <a ;" ) ) answer = __main__.fixHTMLCharsAdvanced( __main__.strbetween( res.text, "alert('", "')\"" ) ) if riddle != "": __main__.sendMessage( riddle, channel ) if answer != "": # Use a timer so we don't block threading.Timer( 15.0, __main__.sendMessage, args=( "Answer: " + answer, channel ) ).start() return True except: return False
def command( message, user, channel ): try: json_data = { "title" : channel, "data" : message, "language" : "text", "expire" : "31536000", "private" : "true" } res = requests.post( "https://paste.kde.org/api/json/create", data=json_data ) print( str( res.text ) ) pasteid = __main__.strbetween( res.text, "\"id\": \"", "\"," ) pastehash = __main__.strbetween( res.text, "\"hash\": \"", "\"" ) if pasteid != "" and pastehash != "": __main__.sendMessage( "https://paste.kde.org/" + pasteid + "/" + pastehash, channel ) else: __main__.sendMessage( "Paste unsuccessful. Try again later!", channel ) return True except: return False
def command( message, user, channel ): try: res = requests.get( "http://isup.me/" + message ) status = __main__.fixHTMLChars( __main__.strbetween( res.text, "<div id=\"container\">", "<p>" ) ).strip() #status = __main__.fixHTMLChars( __main__.strbetween( res.text, "target=\"_blank\">", "</div>" ) ).replace( "</a>", "" ) href = __main__.strbetween( status, "<a href=\"", "class=\"domain\">" ) status = status.replace( "<a href=\"" + href + "class=\"domain\">", "" ) status = status.replace( "</a>", "" ).replace( "</span>", "" ).replace( " ", " " ) if status != "": __main__.sendMessage( status, channel ) else: __main__.sendMessage( "Something went wrong.", channel ) return True except: return False
def command( message, user, channel ): try: res = requests.get( "http://www.thathigh.com/random" ) __main__.sendMessage( __main__.fixHTMLChars( __main__.strbetween( res.text, "<p>", "</p>" ) ), channel ) return True except: return False
def command( message, user, channel ): try: res = requests.get( "http://m.fmylife.com/random" ) __main__.sendMessage( __main__.fixHTMLChars( __main__.strbetween( res.text, "<p class=\"text\">", "</p>" ) ), channel ) return True except: return False
def command( message, user, channel ): try: res = requests.get( "http://dictionary.reference.com/wordoftheday/" ) __main__.sendMessage( "Word of the Day: " + __main__.strbetween( res.text, "<title>Get the Word of the Day - ", " |" ), channel ) return True except: return False
def command( message, user, channel ): try: res = requests.get( "http://prestopnik.com/emo_haiku/" ) haiku = __main__.fixHTMLCharsAdvanced( __main__.strbetween( res.text, "<div align=center><BR><BR>", "<BR><BR><BR><BR></div>" ) ) haiku = haiku.replace( "<BR>", " " ) __main__.sendMessage( haiku, channel ) return True except: return False
def command(message, user, channel): try: res = requests.get("http://www.punoftheday.com/cgi-bin/randompun.pl") pun = __main__.fixHTMLChars(__main__.strbetween(res.text, "<p>", "</p>")) if pun != "": __main__.sendMessage(pun, channel) else: __main__.sendMessage("No pun for you!", channel) return True except: return False
def command( message, user, channel ): try: message = message.strip().lower() if message in signs: res = requests.get( "http://my.horoscope.com/astrology/free-daily-horoscope-" + message + ".html" ) horoscope = __main__.fixHTMLCharsAdvanced( __main__.strbetween( res.text, "<div class=\"fontdef1\" style=\"padding-right:10px;\" id=\"textline\">", "</div>" ) ) luckynum = __main__.fixHTMLCharsAdvanced( __main__.strbetween( res.text, "<div class=\"fontultrasma5\"><b>", "</b>" ) ) luckynum = luckynum.replace( "\t", "" ) if horoscope != "": __main__.sendMessage( message + ": " + horoscope, channel ) __main__.sendMessage( "[Lucky Numbers]:" + luckynum, channel ) else: __main__.sendMessage( message + "'s sign not found today. :(", channel ) elif message == "": __main__.sendMessage( "Usage: horoscope [sign]", channel ) else: __main__.sendMessage( "Invalid sign. Valid signs: " + (", ".join( signs )), channel ) return True except: return False
def command( message, user, channel ): try: res = requests.get( "http://www.randominsults.net/" ) insult = __main__.fixHTMLCharsAdvanced( __main__.strbetween( res.text, "<strong><i>", "</i></strong>" ) ) if insult != "": __main__.sendMessage( message + ": " + insult, channel ) else: __main__.sendMessage( "There was a problem. Fix your shit.", channel ) return True except: return False
def command( message, user, channel ): try: res = requests.get( "http://randomfunfacts.com/" ) fact = __main__.fixHTMLChars( __main__.strbetween( res.text, "<font face=\"Verdana\" size=\"4\"><strong><i>", "</i></strong>" ) ) if fact != "": __main__.sendMessage( fact, channel ) else: __main__.sendMessage( "No fact for you!", channel ) return True except: return False
def command(message, user, channel): try: res = requests.get("http://dictionary.reference.com/browse/" + message) wordCased = __main__.fixHTMLChars( __main__.strbetween(res.text, '<meta name="description" content="', " definition, ") ) if wordCased != "": definition = __main__.fixHTMLChars( __main__.strbetween( res.text, '<meta name="description" content="' + wordCased + " definition, ", ' See more."/>' ) ) if definition != "": __main__.sendMessage(message + ": " + definition, channel) else: __main__.sendMessage(message + " was not found.", channel) else: __main__.sendMessage(message + " was not found.", channel) return True except: return False
def command( message, user, channel ): try: if message == "" or message == " ": __main__.sendMessage( "Usage: geoip [ip.add.re.ss/domain.name]", channel ) return True res = requests.get( "http://freegeoip.net/json/" + message ) ip = __main__.strbetween( res.text, "\"ip\":\"", "\"," ) latitude = __main__.strbetween( res.text, "\"latitude\":", ",\"" ) longitude = __main__.strbetween( res.text, "\"longitude\":", ",\"" ) #countryCode = __main__.strbetween( res.text, "\"country_code\":\"", "\"," ) countryName = __main__.strbetween( res.text, "\"country_name\":\"", "\"," ) #regionCode = __main__.strbetween( res.text, "\"region_code\":\"", "\"," ) regionName = __main__.strbetween( res.text, "\"region_name\":\"", "\"," ) city = __main__.strbetween( res.text, "\"city\":\"", "\"," ) #zipcode = __main__.strbetween( res.text, "\"zipcode\":\"", "\"," ) if ip != "": # IP has to be there if there was any useful info toSend = "IP: " + ip if city != "" and countryName != "" and regionName != "": toSend = toSend + " | Location: " if city != "": toSend = toSend + city + ", " if regionName != "": toSend = toSend + regionName + ", " if countryName != "": toSend = toSend + countryName if latitude != "" and longitude != "": toSend = toSend + " | Coordinates: " + latitude + "," + longitude if toSend == "IP: " + ip + " | Coordinates: 38,-97": # This is a bullshit result toSend = message + " was not found." __main__.sendMessage( toSend, channel ) else: __main__.sendMessage( message + " was not found.", channel ) return True except: return False
def command(message, user, channel): try: res = requests.get("https://steamdb.info/calculator/?player=" + message) playername = __main__.strbetween(res.text, "<title>", " ยท ") if playername != "Error": construct = playername + ": " table = __main__.strbetween(res.text, "<p><br>[list]", "[/list]</p>") worth = __main__.strbetween(table, "[*][b]Worth:[/b] ", "</p>") if worth != "": construct = construct + worth owned = __main__.strbetween(table, "<p>[*][b]Games owned:[/b] ", "</p>") notplayed = __main__.strbetween(table, "<p>[*][b]Games not played:[/b] ", " [i](") if owned != "" and notplayed != "": played = str(int(owned) - int(notplayed)) construct = construct + " | " + played + "/" + owned + " Games Played/Owned" __main__.sendMessage(construct, channel) return True else: __main__.sendMessage(message + " was not found.", channel) return False return False except: return False
def command( message, user, channel ): try: message = message.strip() if message != "": res = requests.get( "http://tangorin.com/general/" + message ) definition = __main__.fixHTMLChars( __main__.strbetween( res.text, "<span class=\"kana\"><ruby><rb>", "</rb>" ) ) if definition != "": __main__.sendMessage( message + ": " + definition, channel ) else: __main__.sendMessage( message + " was not found.", channel ) else: __main__.sendMessage( "Usage: jdic [words]", channel ) return True except: return False
def command( message, user, channel ): try: res = requests.get( "http://ws.audioscrobbler.com/2.0/user/" + message + "/recenttracks.xml?limit=1" ) txt = __main__.fixHTMLChars( res.text ) artist = __main__.strbetween( txt, "<artist>", "</artist>" ) song = __main__.strbetween( txt, "<name>", "</name>" ) album = __main__.strbetween( txt, "<album>", "</album>" ) if album != "": albumtext = " from the album " + album else: albumtext = "" if "<track nowplaying=\"true\">" in txt: nowplaying = " is listening " else: nowplaying = " last listened " if song != "": __main__.sendMessage( message + nowplaying + "to " + song + " by " + artist + albumtext, channel ) else: __main__.sendMessage( message + " was not found.", channel ) return True except: return False
def command( message, user, channel ): try: message = message.split( " " ) amount = message[0] codeFrom = message[1] codeTo = message[2] res = requests.get( "http://www.mobilecurrencyconverter.com/index.php?cur_n=" + amount + "&cur_f=" + codeFrom + "&cur_t=" + codeTo + "&cur_s=major&a=Y" ) rate = __main__.fixHTMLChars( __main__.strbetween( res.text, "</font><br/><font class=\"cr_cv1\">(", ")</font>" ) ) if " " in rate: while " " in rate: rate = rate.replace( " ", " " ) rate = rate.strip() if rate != "" and rate != "1 = 0.00": __main__.sendMessage( rate, channel ) else: __main__.sendMessage( "No conversion found, make sure you write the proper currency code.", channel ) return True except: return False