def autoDownloadMap(self, map_name, parent=None): grabber = LiquipediaGrabber() try: QApplication.setOverrideCursor(Qt.WaitCursor) sc2map = grabber.get_map(map_name) except MapNotFound: QMessageBox.critical( self, _("Map not found"), _('"{}" was not found on Liquipedia.').format(map_name)) return finally: QApplication.restoreOverrideCursor() map_name = sc2map.get_name() try: QApplication.setOverrideCursor(Qt.WaitCursor) images = grabber.get_images(sc2map.get_map_images()) image = "" for size in sorted(images): if not image or size <= 2500 * 2500: image = images[size] url = grabber._base_url + image if parent is None: parent = self.view downloader = MapDownloader(parent, map_name, url) downloader.download() if map_name not in scctool.settings.maps: scctool.settings.maps.append(map_name) except Exception: raise finally: QApplication.restoreOverrideCursor()
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')
def addFromLquipedia(self): """Add a map from Liquipedia.""" grabber = LiquipediaGrabber() search_str = '' while True: search_str, ok = QInputDialog.getText(self, _('Map Name'), _('Map Name') + ':', text=search_str) search_str.strip() try: if ok and search_str: if search_str.lower() == 'tbd': QMessageBox.critical( self, _("Error"), _('"{}" is not a valid map name.').format( search_str)) continue try: QApplication.setOverrideCursor(Qt.WaitCursor) sc2map = grabber.get_map(search_str) except MapNotFound: QMessageBox.critical( self, _("Map not found"), _('"{}" was not found on Liquipedia.').format( search_str)) continue finally: QApplication.restoreOverrideCursor() map_name = sc2map.get_name() if (map_name in scctool.settings.maps): buttonReply = QMessageBox.warning( self, _("Duplicate Entry"), _("Map {} is already in list! Overwrite?".format( map_name)), QMessageBox.Yes | QMessageBox.No, QMessageBox.No) if buttonReply == QMessageBox.No: break else: self.controller.deleteMap(map_name) try: QApplication.setOverrideCursor(Qt.WaitCursor) images = grabber.get_images(sc2map.get_map_images()) image = "" for size in sorted(images): if not image or size <= 2500 * 2500: image = images[size] url = grabber._base_url + image downloader = MapDownloader(self, map_name, url) downloader.download() if map_name not in scctool.settings.maps: scctool.settings.maps.append(map_name) items = self.maplist.findItems(map_name, Qt.MatchExactly) if len(items) == 0: item = QListWidgetItem(map_name) self.maplist.addItem(item) self.maplist.setCurrentItem(item) else: self.maplist.setCurrentItem(items[0]) self.changePreview() except Exception: raise finally: QApplication.restoreOverrideCursor() except Exception as e: module_logger.exception("message") QMessageBox.critical(self, _("Error"), str(e)) break