Example #1
0
 def getLastMatch(self, skip_num=0):
     self.fetchProfile()
     
     topparts = self._profile_html.split('<!-- MATCH HISTORY -->', 1)
     if len(topparts) == 1:
         return None
     
     
     matches = topparts[1].split('<!-- MASTERIES -->', 1)[0]
     split_matches = matches.split('<div class="match_details">')
     if len(split_matches) == 1:
         return None
     
     match_html = split_matches[1+skip_num]
     r = self.lastmatch_re.search(match_html)
     
     if not r:
         return None
     
     d = r.groupdict()
     champion_name = d['champion'].title()
     win = d['win_or_loss'] == 'Win'
     game_type = d['game_type']
     kills = d['kills']
     deaths = d['deaths']
     assists = d['assists']
     cs = d['cs']
     gold = d['gold']
     duration = stripHTML(d['game_length'])
     how_long_ago = d['how_long_ago']
     
     matchstats = SummonerMatchStats('lolking', self.summoner_name, champion_name, win, game_type, kills, deaths, assists, cs, gold, duration, how_long_ago)
     
     return matchstats
Example #2
0
 def MWDefine(cls, word):
     try:
         c = getWebpage("http://www.merriam-webster.com/dictionary/%s" % urllib.quote(word))
     except:
         c = ""
     #<b>1
     valid = True
     try:
         c = c.split('<span class="ssens">',1)[1]
         c = c.split('</span></div>')[0]
         
         if c.find('<span class="ssens">') >= 0:
             c = c.split('<span class="ssens">')[0]
                 
         valid = len(c) > 1
     except:
         valid = False
         
     if valid:
         c = stripHTML(c).strip()
         if c.find(": ") == 0:
             c = c[2:]
         if len(c) > 150:
             c = c[:150]+"..."
         return [True, c]
     else:
         return [False,""]
Example #3
0
 def UrbanDefine(cls, word):
     try:
         c = getWebpage("http://www.urbandictionary.com/define.php?term=%s" % urllib.quote(word))
     except:
         c = ""
 
     ud_def_regex = """<div class='word'>.*?<a .*?>(.+?)</a>.*?<div class='meaning'>(.+?)</div>"""
     c = re.findall(ud_def_regex, c, re.MULTILINE| re.DOTALL)
     if len(c) > 0:
         word_result = stripHTML(c[0][0])
         def_result = stripHTML(c[0][1])
         def_result = def_result.replace('\n',' ')
         def_result = def_result.replace('  ',' ')
         def_result = def_result.replace('  ',' ')
         def_result = def_result.replace('  ',' ')
         if len(def_result) > 300:
             def_result = def_result[:300]+"..."
         return [True,word_result,def_result]
     else:
         return [False,None,None]
Example #4
0
 def UrbanDefine(cls, word):
     try:
         c = getWebpage("http://www.urbandictionary.com/define.php?term=%s" % urllib.quote(word))
     except:
         c = ""
 
     ud_def_regex = """<div class="definition">(.+?)</div>"""
     c = re.findall(ud_def_regex, c, re.MULTILINE| re.DOTALL)
     if len(c) > 0:
         c = stripHTML(c[0])
         c = c.replace('\n',' ')
         c = c.replace('  ',' ')
         c = c.replace('  ',' ')
         c = c.replace('  ',' ')
         if len(c) > 300:
             c = c[:300]+"..."
         return [True,c]
     else:
         return [False,""]
Example #5
0
 def GoogleDefine(cls, word):
     closing_string = "</li>"
     starting_string = """<li style="list-style-type:decimal">"""
     try:
         c = getWebpage("http://www.google.com/search?hl=en&lr=&safe=off&c2coff=1&q=%s&btnG=Search" % urllib.quote("define:\"" + word + "\""))
     except:
         c = ""
     c = c.replace("\r","").replace("\n","")
     
     if c.find(starting_string) < 0:
         return [False,""]
     
     c = c.split(starting_string,1)[1]
     if c.find(closing_string) < 0:
         return [False,""]
     
     result = c.split(closing_string)[0].strip()
     if(result.find("<br>")):
         result = result.split("<br>")[0]
     if len(result) > 150:
         result = result[:150]+"..."
     result = stripHTML(result)
     return [True,result]
Example #6
0
    def processCommand(self, message, trigger, arguments):
        assert isinstance(message, Message.Message)
        assert isinstance(self._chatbot, ChatBot)

        args = arguments.strip()
        if args == "":
            return "You must provide a movie name to get a review for."
        else:
            rotten = getWebpage("http://www.rottentomatoes.com/search/search.php?searchby=movies&search=%s" % urllib.quote(args))
            rotten = rotten.replace("\n","").replace("\r","")
            
            if rotten.find("Search Results for :") > -1:
                rotten_regex0 = '<ul id="movie_results_ul".*?<a target="_top" href="/m/(?P<url>[^"]+)'
                #rotten_regex0 = '<ul id="movie_results_ul".*?<a target="_top" href="/m/(?P<url>[^"]+)[^>]+>(?P<movie_name>[^<]+)</a>'
                redirect = re.findall(rotten_regex0, rotten, re.MULTILINE)
                if len(redirect) >= 1:
                    rotten = getWebpage("http://www.rottentomatoes.com/m/%s/" % redirect[0])
                    rotten = rotten.replace("\n","").replace("\r","")
            
            rotten_regex1 = """<span itemprop="ratingValue" id="all-critics-meter" class="meter certified numeric ">(\d+)</span>"""
            review = re.findall(rotten_regex1, rotten, re.MULTILINE)
            if len(review) != 1:
                found_freshness = False
                freshness = ""
            else:
                found_freshness = True
                freshness = review[0]
            rotten_regex2 = """Average Rating: <span>([^<]+)</span><br />"""
            review = re.findall(rotten_regex2, rotten, re.MULTILINE)
            if len(review) > 0:
                found_avg_rating = True
                avg_rating = review[0]
            else:
                found_avg_rating = False
                avg_rating = ""
            
            
            
            rotten_regexReview = """<p class="critic_consensus">(.+?)</p>"""
            review = re.findall(rotten_regexReview, rotten, re.MULTILINE)
            if len(review) > 0:
                found_critic_consensus = True
                critic_consensus = review[0]
            else:
                found_critic_consensus = False
                critic_consensus = ""
    
            if found_freshness or found_avg_rating:
                rotten_regex3 = """<title>([^<]+) - Rotten Tomatoes</title>"""
                review = re.findall(rotten_regex3, rotten, re.MULTILINE)
                if len(review) != 1:
                    movie_title = args
                else:
                    movie_title = review[0].split(" - ")[0]
                response = ""
                if found_freshness and found_avg_rating:
                    response += "'%s' recieved a freshness score of %s%% from rottentomatos.com with an average rating of %s." % (movie_title, freshness, avg_rating.strip())
                elif found_avg_rating:
                    response += "'%s' recieved an average rating of %s." % (movie_title, avg_rating.strip())
                elif found_freshness:
                    response += "'%s' recieved a freshness score of %s%% from rottentomatos.com." % (movie_title, freshness)
                    
                
                if found_critic_consensus:
                    if len(response) > 0:
                        response = response + "\n"
                    response = response + "\"%s\"" % (stripHTML(critic_consensus))
                    
                return response
                
            else:
                return "I haven't seen '%s'." % args