def main(): check_boundary = True if (config.MAP_START[0] == 0 and config.MAP_START[1] == 0) or (config.MAP_END[0] == 0 and config.MAP_END[1] == 0): check_boundary = False else: north = max(MAP_START[0], MAP_END[0]) south = min(MAP_START[0], MAP_END[0]) east = max(MAP_START[1], MAP_END[1]) west = min(MAP_START[1], MAP_END[1]) all_forts = [fort for fort in database.get_forts(session)] print('{} forts find in database. Start downloading.'.format( len(all_forts))) for fort in all_forts: if fort.url is not None: in_boundary = True if check_boundary == True: lat_check = (fort.lat - north) * (fort.lat - south) lon_check = (fort.lon - east) * (fort.lon - west) if lat_check <= 0.0 and lon_check <= 0.0: in_boundary = True else: in_boundary = False if in_boundary == True: filename = url_image_path + str(fort.id) + '.jpg' print('Downloading', filename) download_img(str(fort.url), str(filename)) session.close()
def __init__(self): if len(argv) >= 2: self.config = importlib.import_module(str(argv[1])) else: self.config = importlib.import_module('config') self.all_forts_inside = [] if self.config.SCAN_AREA is not None: LOG.info('Scan-Area is set! Getting Forts...') session = database.Session() all_forts = database.get_forts(session) all_forts_to_download = [] session2 = database.Session() for fort in all_forts: if self.config.SCAN_AREA == 'All': all_forts_to_download.append(fort.id) self.all_forts_inside.append( DBFort(fort.id, fort.lat, fort.lon, 0)) if fort.lat is not None and fort.lon is not None and self.config.SCAN_AREA.contains( Point(fort.lat, fort.lon)): self.all_forts_inside.append( DBFort(fort.id, fort.lat, fort.lon, 0)) if fort.id not in all_forts_to_download: all_forts_to_download.append(fort.id) nearby_ids = database.get_fort_ids_within_range( session2, all_forts, 800, fort.lat, fort.lon) for fort_id in nearby_ids: if fort_id not in all_forts_to_download: all_forts_to_download.append(fort_id) session2.close() LOG.info('Found {} Gyms Gyms in Scan-Area'.format( len(self.all_forts_inside))) for fort in all_forts: if fort.id in all_forts_to_download: image_file = Path(os.getcwd() + '/url_img/' + str(fort.id) + '.jpg') if not os.path.isfile(image_file) and fort.url is not None: LOG.info( 'Found gym in Scan-Area without stored image! Downloading image for {}' .format(fort.id)) download_img(str(fort.url), str(image_file)) if self.config.DEVICE_LIST is None: LOG.error('SCAN_AREA set but DEVICE_LIST is empty! Skipping') session.commit() session.close() time.sleep(1) if self.config.ENABLE_NEARBY: for i in range(self.config.NEARBY_PROCESSES): self.restart_nearby(i) if self.config.ENABLE_CROP: for i in range(self.config.CROP_PROCESSES): self.restart_crop(i) if self.config.ENABLE_FINDFORT: for i in range(self.config.FINDFORT_PROCESSES): self.restart_findfort(i) if self.config.ENABLE_CONTROL and self.config.SCAN_AREA is not None and self.config.DEVICE_LIST is not None: self.restart_devicecontroller() self.restart_healthcheck()