def test_liquipedia(): grabber = LiquipediaGrabber() mappool = list(grabber.get_ladder_mappool()) assert len(mappool) == 7 stats = list(grabber.get_map_stats(mappool)) assert len(stats) == len(mappool) for map_stats in stats: assert map_stats['map'] in mappool
class MapStatsThread(TasksThread): newMapData = pyqtSignal(str, object) newMapPool = pyqtSignal(object) def __init__(self, manager): super().__init__() self.__manager = manager self.__grabber = LiquipediaGrabber() self.setTimeout(30) self.addTask('refresh_data', self.__refresh_data) self.addTask('refresh_stats', self.__refresh_stats) self.addTask('refresh_mappool', self.__refresh_mappool) def setMaps(self, maps, full=False): if full: self.__fullmaps = maps else: self.__maps = maps def __refresh_data(self): try: map = self.__fullmaps.pop() try: liquipediaMap = self.__grabber.get_map(map) stats = liquipediaMap.get_stats() info = liquipediaMap.get_info() data = dict() data['tvz'] = stats['tvz'] data['zvp'] = stats['zvp'] data['pvt'] = stats['pvt'] data['creator'] = info['creator'] data['size'] = info['size'] data['spawn-positions'] = info['spawn-positions'] data['refreshed'] = int(time.time()) self.newMapData.emit(map, data) module_logger.info('Map {} found.'.format(map)) except MapNotFound: module_logger.info('Map {} not found.'.format(map)) except ConnectionError: module_logger.info('Connection Error for map {}.'.format(map)) except Exception as e: module_logger.exception("message") except IndexError: self.deactivateTask('refresh_data') def __refresh_stats(self): try: for stats in self.__grabber.get_map_stats(self.__maps): map = stats['map'] data = dict() data['tvz'] = stats['tvz'] data['zvp'] = stats['zvp'] data['pvt'] = stats['pvt'] data['refreshed'] = int(time.time()) module_logger.info('Map {} found.'.format(map)) self.newMapData.emit(map, data) finally: self.deactivateTask('refresh_stats') def __refresh_mappool(self): try: mappool = list(self.__grabber.get_ladder_mappool()) self.newMapPool.emit(mappool) module_logger.info('Current map pool found.') finally: self.deactivateTask('refresh_mappool')