示例#1
0
 def search_game(self, title):
     """Return a list of Game objects for a query for the given title."""
     all_games = []
     encoded_title = helper.encode(title)
     # full game search url
     url = helper.gamefaqsURL_search_game + encoded_title
     soup = helper.get_bs4(url)
     tags = soup.find_all("div", {"class": "pod"})
     for tag in tags:
         criteria_tag = tag.find("h2")
         # only include games under best matches category
         if criteria_tag and criteria_tag.text in search_matches:
             best_matches = tag.find_all("tr")
             for match in best_matches:
                 # get game platform
                 p = match.find("td", {"class": "rmain"}).text
                 platform = p.replace(" ", "").replace("\r\n", "")
                 info = match.find("td", {"class": "rtitle"})
                 # get game url
                 game_url = helper.gamefaqsURL_base + info.contents[1]["href"]
                 # get game title
                 game_title = info.text.replace("\n", "")
                 obj = game.Game(game_url, dict(title=game_title,
                                                 platform=platform))                                           
                 all_games.append(obj)
             break
     return all_games
示例#2
0
 def get_top100_games(self):
     """Return the list of the top 100 most popular games today."""
     games_list = []
     soup = helper.get_bs4(helper.gamefaqsURL_top100)
     items = soup.find("tbody").find_all("tr")
     for elem in items:
         tag = elem.find("a")
         url = helper.gamefaqsURL_base + tag["href"]
         title = tag.text
         platform = elem.find_all("td")[4].text
         games_list.append(game.Game(url, dict(title=title, 
                                               platform=platform)))
     return games_list
示例#3
0
 def search_company(self, name, limit=40):
     """Returns a list of Company objects for a query for the given name.
     
     The maximum number of companies to be returned is set by limit.
     """
     companies = []
     encoded_name = helper.encode(name)
     # full company search url
     url =  helper.gamefaqsURL_search_company + encoded_name
     soup = helper.get_bs4(url)
     company_tags = soup.find_all("table")[1].find_all("a")
     count = 0
     for tag in company_tags:
         companies.append(company.Company(helper.gamefaqsURL_base + tag["href"],
                                          dict(name=tag.text)))
         count += 1
         if (count >= limit):
             break
     return companies
示例#4
0
 def find_game_keys(self, infosets):
     """Returns the game keys, values for the given infosets."""
     info = {}
     if "general" in infosets:
         # get game esrb rating 
         for tag in self.soup.find_all("span"):
             if tag.has_attr("class") and "esrb_logo" in tag['class']:
                 info["esrb"] = tag.get_text()[:-3] # remove whitespaces and other char            
         # get game description
         desc = self.soup.find("div", {"class": "desc"}).get_text()
         desc = " ".join(desc.split()) # remove newlines
         info["description"] = desc.replace("'", "")
         # get game platform long
         info["platform_long"] =  self.soup.find("li", {"class": "core-platform"}).get_text()
         companies = []
         for tag in self.soup.find_all("a"):
             if tag.has_attr("href"):
                 # get game release date
                 if tag["href"].endswith("/data") and tag.get_text() != "Release Data":
                     info["release_date"] = tag.get_text()[:-2] # removes whitespace and >>
                 if "/features/company/" in tag['href']:
                     company_name = tag.get_text().replace("'", "''")
                     url = helper.gamefaqsURL_base + tag["href"]
                     companies.append(company.Company(url, dict(name=company_name)))
         # get game companies
         info["companies"] = companies
     
     if "rating" in infosets:
         for tag in self.soup.find_all("a"):
             if tag.has_attr("href"):
                 # get user rating 
                 if tag["href"].endswith("rate"):
                     info["user_rating"] = tag.get_text()[:-4] # remove whitespaces and other char
                 # get game difficulty
                 if tag["href"].endswith("diff"):
                     info["difficulty"] = tag.get_text()
                 # get game length (hrs)
                 if tag["href"].endswith("time"):
                     info["length"] = tag.get_text()[:-6] # remove whitespace and 'hours'             
         # get game metacritic score
         metascore_tag = self.soup.find_all("div", {'class':'score metacritic_mid'}) + \
                         self.soup.find_all("div", {'class':'score metacritic_high'}) + \
                         self.soup.find_all("div", {'class':'score metacritic_low'})
         if metascore_tag:
             info["metascore"] = metascore_tag[0].get_text()
     
     if "cheats" in infosets:
         codes = []
         unlockables = []
         url_full = self.url + "/cheats"
         bsoup = helper.get_bs4(url_full)
         table_tags = bsoup.find_all("table")
         for t in table_tags:
             if t.find_all("th", text="Code"):
                 for i in t.find_all("tr")[1:]:
                     val = i.contents
                     effect = val[0].text
                     code = val[1].text
                     codes.append(cheats.Code(effect, code))
             elif t.find_all("th", text="Unlockable"):
                 for j in t.find_all("tr")[1:]:
                     val = j.contents
                     unlockable = val[0].text
                     howto = val[1].text
                     unlockables.append(cheats.Unlockable(unlockable, howto))
         info["codes"] = codes
         info["unlockables"] = unlockables
     return info
示例#5
0
 def save(self, url):
     """Save bs4 object of url webpage."""
     self.url = url
     self.soup = helper.get_bs4(url)