def getCompletedGame(self, matchID): game = None try: db = self.sqlHelper.getConnection() with closing(db.cursor()) as cur: cur.execute( """SELECT * FROM `complete_matches` WHERE `match_id` = %s""", (matchID, )) result = cur.fetchone() if not result is None: game = Game(result[2], result[0], "Recent", result[1], result[3], result[4], result[5], result[6]) game.setScore(result[7]) except Exception as e: print(traceback.format_exc()) finally: db.close() return game
def updateMatches(self): threading.Timer(60 * 60, self.updateMatches).start() gamesToUpdate = ["csgo", "lol", "dota2", "hearth", "hots"] csgoMatchLink = "http://www.gosugamers.net/counterstrike/gosubet" dotaMatchLink = "http://www.gosugamers.net/dota2/gosubet" lolMatchLink = "http://www.gosugamers.net/lol/gosubet" hearthMatchLink = "http://www.gosugamers.net/hearthstone/gosubet" hotsMatchLink = "http://www.gosugamers.net/heroesofthestorm/gosubet" self.clearLists() for gameType in gamesToUpdate: try: link = "" if gameType == "csgo": link = csgoMatchLink elif gameType == "lol": link = lolMatchLink elif gameType == "dota2": link = dotaMatchLink elif gameType == "hearth": link = hearthMatchLink elif gameType == "hots": link = hotsMatchLink req = urllib2.Request( link, headers={ 'User-Agent': "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36" }) web_page = urllib2.urlopen(req).read() bs = BeautifulSoup(web_page) match_columns = bs.findAll("div", attrs={"id": "col1"}) boxes = match_columns[0].findAll("div", attrs={"class": "box"}) for box in boxes: header = "" h1 = box.find("h1") if h1 is None: h2 = box.find("h2") header = h2.text.strip() else: header = h1.text.strip() if header.find("Live") != -1: header = "Live" elif header.find("Recent") != -1: header = "Recent" elif header.find("Upcoming") != -1: header = "Upcoming" table = box.find("table", attrs={"class": "simple"}) if not table is None: matches = table.find("tbody") rows = matches.findAll("tr") for row in rows: cols = row.findAll("td") match_info = cols[0].find("a", attrs={"class": "match"}) link = match_info['href'] id = match_info['href'].split("/")[-1].split( "-")[0] opponent1 = match_info.find("span", attrs={ "class": "opp1" }).text.strip() bet1 = match_info.find("span", attrs={ "class": "bet1" }).text.strip() opponent2 = match_info.find("span", attrs={ "class": "opp2" }).text.strip() bet2 = match_info.find("span", attrs={ "class": "bet2" }).text.strip() # Add game to list game = Game(gameType, id, header, link, opponent1, opponent2, bet1, bet2) if header == "Upcoming": timeCol = cols[1].find( "span", attrs={"class": "live-in"}) timeUntil = timeCol.text.strip() game.setTime(timeUntil) elif header == "Recent": winnerScore = cols[1].find("span", attrs={ "class": "hidden" }).text.strip() game.setScore(winnerScore) self.queryHelper.insertComplete(game) if gameType == "csgo": if header == "Live": self.csgoLiveList.append(game) elif header == "Upcoming": self.csgoUpcomingList.append(game) elif header == "Recent": self.csgoRecentList.append(game) else: raise Exception("Parsed invalid header") elif gameType == "lol": if header == "Live": self.lolLiveList.append(game) elif header == "Upcoming": self.lolUpcomingList.append(game) elif header == "Recent": self.lolRecentList.append(game) else: raise Exception("Parsed invalid header") elif gameType == "dota2": if header == "Live": self.dotaLiveList.append(game) elif header == "Upcoming": self.dotaUpcomingList.append(game) elif header == "Recent": self.dotaRecentList.append(game) else: raise Exception("Parsed invalid header") elif gameType == "hearth": if header == "Live": self.hearthLiveList.append(game) elif header == "Upcoming": self.hearthUpcomingList.append(game) elif header == "Recent": self.hearthRecentList.append(game) else: raise Exception("Parsed invalid header") elif gameType == "hots": if header == "Live": self.hotsLiveList.append(game) elif header == "Upcoming": self.hotsUpcomingList.append(game) elif header == "Recent": self.hotsRecentList.append(game) else: raise Exception("Parsed invalid header") except Exception as e: print("Error retrieving game data") print(traceback.format_exc())