def get_avg_data_time(self, minutes=False, grouped=True, worker=False): logger.debug('Fetching group detection count from db') grouped_query = "" query_where = "" worker_where = "" if worker: worker_where = ' and worker = \'%s\' ' % str(worker) if grouped: grouped_query = ", day(FROM_UNIXTIME(period)), hour(FROM_UNIXTIME(period)), transporttype" if minutes: minutes = datetime.now().replace( minute=0, second=0, microsecond=0) - timedelta(minutes=int(minutes)) query_where = ' and (period) >= unix_timestamp(\'%s\') ' % str( minutes) query_date = "unix_timestamp(DATE_FORMAT(FROM_UNIXTIME(period), '%y-%m-%d %k:00:00'))" query = ( "SELECT %s, if(transporttype=0,'Teleport',if(transporttype=1,'Walk', " "'other')), worker, count(fix_ts), avg(data_ts-fix_ts) as data_time, walker from trs_stats_location_raw " "where success=1 and type in (0,1) and (walker='mon_mitm' or walker='iv_mitm' or walker='pokestops') " "%s %s group by worker %s" % (str(query_date), (query_where), str(worker_where), str(grouped_query))) res = self._db_exec.execute(query) return res
def parse_geofences_file(geo_resource, excluded): geofences = [] # Read coordinates of excluded areas from file. if geo_resource: lines = geo_resource['fence_data'] first_line = True for line in geo_resource['fence_data']: line = line.strip() if len(line) == 0: # Empty line. continue elif line.startswith("["): # Name line. name = line.replace("[", "").replace("]", "") geofences.append({ 'excluded': excluded, 'name': name, 'polygon': [] }) logger.debug('Found geofence: {}', name) first_line = False else: # Coordinate line. if first_line: # Geofence file with no name geofences.append({ 'excluded': excluded, 'name': 'unnamed', 'polygon': [] }) logger.debug('Found geofence with no name') first_line = False lat, lon = line.split(",") LatLon = {'lat': float(lat), 'lon': float(lon)} geofences[-1]['polygon'].append(LatLon) return geofences
def start_worker(self): logger.info("Worker {} started in configmode", str(self._origin)) self._mapping_manager.register_worker_to_routemanager( self._routemanager_name, self._origin) logger.debug("Setting device to idle for routemanager") self._db_wrapper.save_idle_status(self._dev_id, True) logger.debug("Device set to idle for routemanager {}", str(self._origin)) while self.check_walker() and not self._stop_worker_event.is_set(): if self._args.config_mode: time.sleep(10) else: position_type = self._mapping_manager.routemanager_get_position_type( self._routemanager_name, self._origin) if position_type is None: logger.warning( "Mappings/Routemanagers have changed, stopping worker to be created again" ) self._stop_worker_event.set() time.sleep(1) else: time.sleep(10) self.set_devicesettings_value('finished', True) self._mapping_manager.unregister_worker_from_routemanager( self._routemanager_name, self._origin) try: self._communicator.cleanup() finally: logger.info("Internal cleanup of {} finished", str(self._origin)) return
def preadd_job(self, origin, job, id_, type, globalid=None): logger.info( 'Adding Job {} for Device {} - File/Job: {} (ID: {})'.format( str(type), str(origin), str(job), str(id_))) globalid = globalid if globalid is not None else id_ if globalid not in self._globaljoblog: self._globaljoblog[globalid] = {} self._globaljoblog[globalid]['laststatus'] = None self._globaljoblog[globalid]['lastjobend'] = None if jobType[type.split('.')[1]] == jobType.CHAIN: for subjob in self._commands[job]: logger.debug(subjob) self.add_job(globalid=globalid, origin=origin, file=subjob['SYNTAX'], id_=int(time.time()), type=subjob['TYPE'], waittime=subjob.get('WAITTIME', 0), redo=self._globaljoblog[globalid].get( 'redo', False), fieldname=subjob.get('FIELDNAME', 'unknown'), jobname=job) time.sleep(1) else: self.add_job(globalid=globalid, origin=origin, file=job, id_=int(id_), type=type)
def parse_ggl(self, xml, mail: str) -> bool: if xml is None: logger.warning( 'Something wrong with processing - getting None Type from Websocket...' ) return False try: parser = ET.XMLParser(encoding="utf-8") xmlroot = ET.fromstring(xml, parser=parser) for item in xmlroot.iter('node'): if mail.lower() in str(item.attrib['text']).lower(): logger.info("Found mail {}", self.censor_account(str(item.attrib['text']))) bounds = item.attrib['bounds'] logger.debug("Bounds {}", str(item.attrib['bounds'])) match = re.search(r'^\[(\d+),(\d+)\]\[(\d+),(\d+)\]$', bounds) click_x = int(match.group(1)) + ( (int(match.group(3)) - int(match.group(1))) / 2) click_y = int(match.group(2)) + ( (int(match.group(4)) - int(match.group(2))) / 2) logger.debug('Click ' + str(click_x) + ' / ' + str(click_y)) self._communicator.click(click_x, click_y) time.sleep(2) return True except Exception as e: logger.error('Something wrong while parsing xml: {}'.format( str(e))) return False time.sleep(2) logger.warning('Dont find any mailaddress...') return False
def stops_from_db(self, geofence_helper): """ Retrieve all the pokestops valid within the area set by geofence_helper :return: numpy array with coords """ logger.debug("DbWrapper::stops_from_db called") minLat, minLon, maxLat, maxLon = geofence_helper.get_polygon_from_fence( ) query = ("SELECT latitude, longitude " "FROM pokestop " "WHERE (latitude >= {} AND longitude >= {} " "AND latitude <= {} AND longitude <= {}) ").format( minLat, minLon, maxLat, maxLon) res = self.execute(query) list_of_coords: List[Location] = [] for (latitude, longitude) in res: list_of_coords.append(Location(latitude, longitude)) if geofence_helper is not None: geofenced_coords = geofence_helper.get_geofenced_coordinates( list_of_coords) return geofenced_coords else: return list_of_coords
def stops_from_db_unvisited(self, geofence_helper: GeofenceHelper, origin: str): logger.debug("DbWrapper::stops_from_db_unvisited called") minLat, minLon, maxLat, maxLon = geofence_helper.get_polygon_from_fence( ) query = ( "SELECT pokestop.latitude, pokestop.longitude " "FROM pokestop " "LEFT JOIN trs_visited ON (pokestop.pokestop_id = trs_visited.pokestop_id AND trs_visited.origin='{}') " "WHERE pokestop.latitude >= {} AND pokestop.longitude >= {} " "AND pokestop.latitude <= {} AND pokestop.longitude <= {} " "AND trs_visited.origin IS NULL").format(origin, minLat, minLon, maxLat, maxLon) res = self.execute(query) unvisited: List[Location] = [] for (latitude, longitude) in res: unvisited.append(Location(latitude, longitude)) if geofence_helper is not None: geofenced_coords = geofence_helper.get_geofenced_coordinates( unvisited) return geofenced_coords else: return unvisited
def weather(self, origin, map_proto, received_timestamp): """ Update/Insert weather from a map_proto dict """ logger.debug( "DbPogoProtoSubmit::weather called with data received from {}", str(origin)) cells = map_proto.get("cells", None) if cells is None: return False query_weather = ( "INSERT INTO weather (s2_cell_id, latitude, longitude, cloud_level, rain_level, wind_level, " "snow_level, fog_level, wind_direction, gameplay_weather, severity, warn_weather, world_time, " "last_updated) " "VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s) " "ON DUPLICATE KEY UPDATE fog_level=VALUES(fog_level), cloud_level=VALUES(cloud_level), " "snow_level=VALUES(snow_level), wind_direction=VALUES(wind_direction), " "world_time=VALUES(world_time), gameplay_weather=VALUES(gameplay_weather), " "last_updated=VALUES(last_updated)") list_of_weather_args = [] for client_weather in map_proto["client_weather"]: # lat, lng, alt = S2Helper.get_position_from_cell(weather_extract["cell_id"]) time_of_day = map_proto.get("time_of_day_value", 0) list_of_weather_args.append( self._extract_args_single_weather(client_weather, time_of_day, received_timestamp)) self._db_exec.executemany(query_weather, list_of_weather_args, commit=True) return True
async def __prep_settings(self, origin: str) -> Optional[WalkerConfiguration]: last_known_state = {} client_mapping = self.__mapping_manager.get_devicemappings_of(origin) devicesettings = self.__mapping_manager.get_devicesettings_of(origin) logger.info("Setting up routemanagers for {}", str(origin)) walker_configuration: Optional[ WalkerConfiguration] = await self.__get_walker_settings( origin, client_mapping, devicesettings) if walker_configuration is None: # logging is done in __get_walker_settings... return None if walker_configuration.walker_area_name not in self.__mapping_manager.get_all_routemanager_names( ): raise WrongAreaInWalker() logger.debug('Devicesettings {}: {}', str(origin), devicesettings) logger.info( '{} using walker area {} [{}/{}]', str(origin), str( self.__mapping_manager.routemanager_get_name( walker_configuration.walker_area_name)), str(walker_configuration.walker_index + 1), str(walker_configuration.total_walkers_allowed_for_assigned_area)) return walker_configuration
def get_detection_count(self, minutes=False, grouped=True, worker=False): logger.debug('Fetching group detection count from db') grouped_query = "" worker_where = "" if worker and minutes: worker_where = ' and worker = \'%s\' ' % str(worker) if worker and not minutes: worker_where = ' where worker = \'%s\' ' % str(worker) if grouped: grouped_query = ", day(FROM_UNIXTIME(timestamp_scan)), hour(FROM_UNIXTIME(timestamp_scan))" query_where = '' query_date = "unix_timestamp(DATE_FORMAT(from_unixtime(timestamp_scan), '%y-%m-%d %k:00:00'))" if minutes: minutes = datetime.now().replace( minute=0, second=0, microsecond=0) - timedelta(minutes=int(minutes)) query_where = ' where (timestamp_scan) >= unix_timestamp(\'%s\') ' % str( minutes) query = ( "SELECT %s, worker, sum(mon) as Mon, sum(mon_iv) as MonIV, sum(raid) as Raids, sum(quest) as Quests " "FROM trs_stats_detect %s %s " "GROUP BY worker %s " "ORDER BY timestamp_scan" % (str(query_date), str(query_where), str(worker_where), str(grouped_query))) res = self._db_exec.execute(query) return res
def stops(self, origin: str, map_proto: dict): """ Update/Insert pokestops from a map_proto dict """ logger.debug( "DbPogoProtoSubmit::stops called with data received from {}", str(origin)) cells = map_proto.get("cells", None) if cells is None: return False query_stops = ( "INSERT INTO pokestop (pokestop_id, enabled, latitude, longitude, last_modified, lure_expiration, " "last_updated, active_fort_modifier, incident_start, incident_expiration, incident_grunt_type) " "VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s) " "ON DUPLICATE KEY UPDATE last_updated=VALUES(last_updated), lure_expiration=VALUES(lure_expiration), " "last_modified=VALUES(last_modified), latitude=VALUES(latitude), longitude=VALUES(longitude), " "active_fort_modifier=VALUES(active_fort_modifier), incident_start=VALUES(incident_start), " "incident_expiration=VALUES(incident_expiration), incident_grunt_type=VALUES(incident_grunt_type)" ) stops_args = [] for cell in cells: for fort in cell["forts"]: if fort["type"] == 1: stops_args.append(self._extract_args_single_stop(fort)) self._db_exec.executemany(query_stops, stops_args, commit=True) return True
def get_location_raw(self, minutes=False, worker=False): logger.debug('Fetching locations raw data from db') query_where = "" worker_where = "" if worker and minutes: worker_where = ' and worker = \'%s\' ' % str(worker) if worker and not minutes: worker_where = ' where worker = \'%s\' ' % str(worker) if minutes: minutes = datetime.now().replace( minute=0, second=0, microsecond=0) - timedelta(minutes=int(minutes)) query_where = ' where (period) >= unix_timestamp(\'%s\') ' % str( minutes) query_date = "unix_timestamp(DATE_FORMAT(FROM_UNIXTIME(period), '%y-%m-%d %k:00:00'))" query = ( "SELECT %s, lat, lng, if(type=0,'Normal',if(type=1,'PrioQ', if(type=2,'Startup'," "if(type=3,'Reboot','Restart')))), if(success=1,'OK','NOK'), fix_ts, " "if(data_ts=0,fix_ts,data_ts), count, if(transporttype=0,'Teleport',if(transporttype=1,'Walk', " "'other')) from trs_stats_location_raw %s %s order by id asc" % (str(query_date), (query_where), str(worker_where))) res = self._db_exec.execute(query) return res
def get_locations_dataratio(self, minutes=False, grouped=True, worker=False): logger.debug('Fetching group locations dataratio from db') grouped_query = "" query_where = "" worker_where = "" if worker and minutes: worker_where = ' and worker = \'%s\' ' % str(worker) if worker and not minutes: worker_where = ' where worker = \'%s\' ' % str(worker) if grouped: grouped_query = ", success, type" if minutes: minutes = datetime.now().replace( minute=0, second=0, microsecond=0) - timedelta(minutes=int(minutes)) query_where = ' where (period) >= unix_timestamp(\'%s\') ' % str( minutes) query_date = "unix_timestamp(DATE_FORMAT(FROM_UNIXTIME(period), '%y-%m-%d %k:00:00'))" query = ( "SELECT %s, worker, count(period), if(type=0,if(success=1,'OK-Normal','NOK-Normal')," "if(success=1,'OK-PrioQ','NOK-PrioQ')) from trs_stats_location_raw " " %s %s and type in(0,1) group by worker %s" % (str(query_date), (query_where), str(worker_where), str(grouped_query))) res = self._db_exec.execute(query) return res
def get_locations(self, minutes=False, grouped=True, worker=False): logger.debug('Fetching group locations count from db') grouped_query = "" query_where = "" worker_where = "" if worker and minutes: worker_where = ' and worker = \'%s\' ' % str(worker) if worker and not minutes: worker_where = ' where worker = \'%s\' ' % str(worker) if grouped: grouped_query = ", day(FROM_UNIXTIME(timestamp_scan)), hour(FROM_UNIXTIME(timestamp_scan))" if minutes: minutes = datetime.now().replace( minute=0, second=0, microsecond=0) - timedelta(minutes=int(minutes)) query_where = ' where (timestamp_scan) >= unix_timestamp(\'%s\') ' % str( minutes) query_date = "unix_timestamp(DATE_FORMAT(FROM_UNIXTIME(timestamp_scan), '%y-%m-%d %k:00:00'))" query = ( "SELECT %s, worker, sum(location_count), sum(location_ok), sum(location_nok) from trs_stats_location " " %s %s group by worker %s" % (str(query_date), (query_where), str(worker_where), str(grouped_query))) res = self._db_exec.execute(query) return res
def connect_token(self): try: self.api.login(gsfId=self.gsfid, authSubToken=self.token) self.valid = True except Exception as err: logger.debug('Unable to login, {}', err) return self.valid
async def get_worker_using_settings(self, origin: str, enable_configmode: bool, communicator: AbstractCommunicator) \ -> Optional[AbstractWorker]: if enable_configmode: return self.get_configmode_worker(origin, communicator) # not a configmore worker, move on adjusting devicesettings etc # TODO: get worker walker_configuration: Optional[ WalkerConfiguration] = await self.__prep_settings(origin) if walker_configuration is None: logger.error("Failed to find a walker configuration for {}", origin) return None logger.debug("Setting up worker for {}", str(origin)) await self.__update_settings_of_origin(origin, walker_configuration) dev_id = self.__mapping_manager.get_all_devicemappings( )[origin]['device_id'] area_id = walker_configuration.walker_settings['walkerarea'] walker_routemanager_mode: WorkerType = self.__mapping_manager.routemanager_get_mode( walker_configuration.walker_area_name) if dev_id is None or area_id is None or walker_routemanager_mode == WorkerType.UNDEFINED: logger.error( "Failed to instantiate worker for {} due to invalid settings found", origin) return None # we can finally create an instance of the worker, bloody hell... # TODO: last_known_state has never been used and got kinda deprecated due to devicesettings... return self.get_worker(origin, walker_routemanager_mode, communicator, dev_id, {}, area_id, walker_configuration.walker_settings, walker_configuration.walker_area_name)
def generate_token_list(self, args) -> List[str]: token_list = [] if args.token_dispenser_user: try: with open(args.token_dispenser_user, 'rb') as fh: for host in fh: if not host.strip(): continue if host.strip() not in fh: token_list.append(host.strip()) except FileNotFoundError: logger.error('Unable to find token file {}', args.token_dispenser_user) if args.token_dispenser: try: with open(args.token_dispenser, 'r') as fh: for host in fh: if not host.strip(): continue if host.strip() not in fh: token_list.append(host.strip()) except FileNotFoundError: logger.error('Unable to find token file {}', args.token_dispenser) logger.debug('Token Dispensers: {}', token_list) return token_list
def __internal_worker_join(self): while not self.__stop_server.is_set() \ or (self.__stop_server.is_set() and not self.__worker_shutdown_queue.empty()): try: next_item: Optional[ Thread] = self.__worker_shutdown_queue.get_nowait() except queue.Empty: time.sleep(1) continue if next_item is not None: logger.info("Trying to join worker thread") try: next_item.join(10) except RuntimeError as e: logger.warning( "Caught runtime error trying to join thread, the thread likely did not start " "at all. Exact message: {}", e) if next_item.is_alive(): logger.debug( "Error while joining worker thread - requeue it") self.__worker_shutdown_queue.put(next_item) else: logger.debug("Done with worker thread, moving on") self.__worker_shutdown_queue.task_done() logger.info("Worker join-thread done")
def stop_from_db_without_quests(self, geofence_helper): logger.debug("DbWrapper::stop_from_db_without_quests called") minLat, minLon, maxLat, maxLon = geofence_helper.get_polygon_from_fence( ) query = ( "SELECT pokestop.latitude, pokestop.longitude " "FROM pokestop " "LEFT JOIN trs_quest ON pokestop.pokestop_id = trs_quest.GUID " "WHERE (pokestop.latitude >= {} AND pokestop.longitude >= {} " "AND pokestop.latitude <= {} AND pokestop.longitude <= {}) " "AND (DATE(from_unixtime(trs_quest.quest_timestamp,'%Y-%m-%d')) <> CURDATE() " "OR trs_quest.GUID IS NULL)").format(minLat, minLon, maxLat, maxLon) res = self.execute(query) list_of_coords: List[Location] = [] for (latitude, longitude) in res: list_of_coords.append(Location(latitude, longitude)) if geofence_helper is not None: geofenced_coords = geofence_helper.get_geofenced_coordinates( list_of_coords) return geofenced_coords else: return list_of_coords
def run(self): # build a private DbWrapper instance... logger.info("Starting MITMDataProcessor") while True: try: item = self.__queue.get() try: items_left = self.__queue.qsize() except NotImplementedError: items_left = 0 logger.debug( "MITM data processing worker retrieved data. Queue length left afterwards: {}", str(items_left)) if items_left > 50: logger.warning( "MITM data processing workers are falling behind! Queue length: {}", str(items_left)) if item is None: logger.warning("Received none from queue of data") break self.process_data(item[0], item[1], item[2]) self.__queue.task_done() except KeyboardInterrupt as e: logger.info("MITMDataProcessor received keyboard interrupt, stopping") break
def download_spawns(self, neLat=None, neLon=None, swLat=None, swLon=None, oNeLat=None, oNeLon=None, oSwLat=None, oSwLon=None, timestamp=None, fence=None): logger.debug("dbWrapper::download_spawns") spawn = {} query_where = "" query = ("SELECT spawnpoint, latitude, longitude, calc_endminsec, " "spawndef, last_scanned, first_detection, last_non_scanned " "FROM `trs_spawn`") if neLat is not None: query_where = (" WHERE (latitude >= {} AND longitude >= {} " " AND latitude <= {} AND longitude <= {}) ").format( swLat, swLon, neLat, neLon) if oNeLat is not None and oNeLon is not None and oSwLat is not None and oSwLon is not None: oquery_where = ( " AND NOT (latitude >= {} AND longitude >= {} " " AND latitude <= {} AND longitude <= {}) ").format( oSwLat, oSwLon, oNeLat, oNeLon) query_where = query_where + oquery_where elif timestamp is not None: tsdt = datetime.utcfromtimestamp( int(timestamp)).strftime("%Y-%m-%d %H:%M:%S") oquery_where = (" AND last_scanned >= '{}' ").format(tsdt) query_where = query_where + oquery_where if fence is not None: query_where = query_where + " where ST_CONTAINS(ST_GEOMFROMTEXT( 'POLYGON(( {} ))'), " \ "POINT(trs_spawn.latitude, trs_spawn.longitude))".format(str(fence)) query = query + query_where res = self.execute(query) for (spawnid, lat, lon, endtime, spawndef, last_scanned, first_detection, last_non_scanned) in res: spawn[spawnid] = { 'id': spawnid, 'lat': lat, 'lon': lon, 'endtime': endtime, 'spawndef': spawndef, 'lastscan': str(last_scanned), 'lastnonscan': str(last_non_scanned), 'first_detection': str(first_detection) } return str(json.dumps(spawn))
def _clear_quests(self, delayadd, openmenu=True): logger.debug('{_clear_quests} called') if openmenu: x, y = self._resocalc.get_coords_quest_menu(self)[0], \ self._resocalc.get_coords_quest_menu(self)[1] self._communicator.click(int(x), int(y)) time.sleep(6 + int(delayadd)) trashcancheck = self._get_trash_positions(full_screen=True) if trashcancheck is None: logger.error('Could not find any trashcan - abort') return logger.info("Found {} trashcan(s) on screen", len(trashcancheck)) # get confirm box coords x, y = self._resocalc.get_confirm_delete_quest_coords(self)[0], \ self._resocalc.get_confirm_delete_quest_coords(self)[1] for trash in range(len(trashcancheck)): logger.info("Delete old quest {}", int(trash) + 1) self._communicator.click(int(trashcancheck[0].x), int(trashcancheck[0].y)) time.sleep(1 + int(delayadd)) self._communicator.click(int(x), int(y)) time.sleep(1 + int(delayadd)) x, y = self._resocalc.get_close_main_button_coords(self)[0], \ self._resocalc.get_close_main_button_coords(self)[1] self._communicator.click(int(x), int(y)) time.sleep(1.5) logger.debug('{_clear_quests} finished') return
def _click_center_button(self, diff, global_dict, i) -> None: (x, y, w, h) = (global_dict['left'][i], global_dict['top'][i], global_dict['width'][i], global_dict['height'][i]) logger.debug("Diff: {}", diff) click_x, click_y = (x + w / 2) / diff, (y + h / 2) / diff logger.debug('Click ' + str(click_x) + ' / ' + str(click_y)) self._communicator.click(click_x, click_y)
def calculate_new_route(self, coords, max_radius, max_coords_within_radius, delete_old_route, calc_type, useS2, S2level, num_procs=0, overwrite_calculation=False, in_memory=False, route_name: str = 'Unknown'): if overwrite_calculation: calc_type = 'quick' self.set_recalc_status(True) if in_memory is False: if delete_old_route: logger.debug("Deleting routefile...") self._data['fields']['routefile'] = [] self.save() new_route = self.getJsonRoute(coords, max_radius, max_coords_within_radius, in_memory, num_processes=num_procs, algorithm=calc_type, useS2=useS2, S2level=S2level, route_name=route_name) self.set_recalc_status(False) return new_route
def get_geofenced_coordinates(self, coordinates): # Import: We are working with n-tuples in some functions be carefull # and do not break compatibility logger.debug('Using matplotlib: {}.', self.use_matplotlib) logger.debug('Found {} coordinates to geofence.', len(coordinates)) geofenced_coordinates = [] for c in coordinates: # Coordinate is not valid if in one excluded area. if self._is_excluded(c): continue # Coordinate is geofenced if in one geofenced area. if self.geofenced_areas: for va in self.geofenced_areas: if self._in_area(c, va): geofenced_coordinates.append(c) break else: geofenced_coordinates.append(c) logger.debug2("Geofenced to {} coordinates", len(geofenced_coordinates)) return geofenced_coordinates
def _close_gym(self, delayadd): logger.debug('{_close_gym} called') x, y = self._resocalc.get_close_main_button_coords(self)[0], \ self._resocalc.get_close_main_button_coords(self)[1] self._communicator.click(int(x), int(y)) time.sleep(1 + int(delayadd)) logger.debug('{_close_gym} called')
def presave_validation(self, ignore_issues=[]): # Validate required data has been set top_levels = ['fields', 'settings'] issues = {} for top_level in top_levels: try: for key, val in self._data[top_level].issues.items(): if key in ignore_issues: continue if not val: continue if key not in issues: issues[key] = [] issues[key] += val except KeyError: continue custom_issues = self.validate_custom() if custom_issues: for key, set_issues in custom_issues.items(): if key not in issues: issues[key] = set_issues elif type(set_issues) is list: issues[key] += set_issues elif type(set_issues) is dict: issues[key].update(set_issues) if issues: logger.debug('Unable to save the resource {} / {}: {}', self.__class__.__name__, self.identifier, issues) raise dm_exceptions.UpdateIssue(**issues)
def token_login(self, token: str) -> bool: try: self.api.login(gsfId=int(self.gsfid), authSubToken=token) self.valid = True except Exception as err: logger.debug('Unable to login, {}', err) return self.valid
def calculate_new_route( self, coords: List[Tuple[str, str]], max_radius: int, max_coords_within_radius: int, delete_old_route: bool, calc_type: str, useS2: bool, S2level: int, num_procs: int = 0, overwrite_calculation: bool = False, in_memory: bool = False, route_name: str = 'Unknown') -> List[Dict[str, float]]: if overwrite_calculation: calc_type = 'quick' self.set_recalc_status(True) if in_memory is False: if delete_old_route: logger.debug("Deleting routefile...") self._data['fields']['routefile'] = [] self.save() new_route = self.getJsonRoute(coords, max_radius, max_coords_within_radius, in_memory, num_processes=num_procs, algorithm=calc_type, useS2=useS2, S2level=S2level, route_name=route_name) self.set_recalc_status(False) return new_route
def generate_stop_list(self): time.sleep(5) stops = self.db_wrapper.stop_from_db_without_quests(self.geofence_helper) logger.info('Detected stops without quests: {}', str(len(stops))) logger.debug('Detected stops without quests: {}', str(stops)) self._stoplist: List[Location] = stops