def _get_vessel_info(self, conn, vessel_name): vessel_info = None results = query_vessel_details(conn, 'name', vessel_name, exact_match=True) for v in results: if settings.USE_MOCK_FLEETMON_DATA or v['name'] == vessel_name: vessel_info = v break return vessel_info
def fetch(self, conn): vessels = db_utils.query(conn, "select distinct mmsi from vessel " "where next_update_time <= %s", (datetime.datetime.utcnow(), )) for v in vessels: mmsi = v[0] try: query_vessel_details(conn, 'mmsi', mmsi, force=True) except Exception, e: logging.error('Server Error: %s', (e,), exc_info=True) conn.rollback() else: conn.commit() gevent.sleep(1)
def _on_get(self, req, resp, conn, **kwargs): search_by = req.get_param('search_by') q = req.get_param('q') if search_by not in ('name', 'imo', 'mmsi', 'cs') or not q: raise ValidationError('INVALID_REQUEST') if search_by == 'cs': search_by = 'name' # TODO: find according name in DB return { 'objects': query_vessel_details(conn, search_by, q), 'res': RESP_RESULT.S }
def _on_get(self, req, resp, conn, **kwargs): search_by = req.get_param('search_by') q = req.get_param('q') if search_by not in ('name', 'imo', 'mmsi', 'cs') or not q: raise ValidationError('INVALID_REQUEST') if search_by == 'cs': search_by = 'name' # TODO: find according name in DB results = getVesselDs().searchVessel(**{search_by: q}) if len(results) > 0 and req.get_param('details') == 'true': results = query_vessel_details(conn, search_by, q) return {'objects': results, 'res': RESP_RESULT.S}
def _on_get(self, req, resp, conn, **kwargs): id_user = req.get_param('id_user') if not id_user: raise ValidationError('INVALID_REQUEST') user_fleets = db_utils.select(conn, "user_fleet", columns=("imo", "mmsi"), where={'id_user': id_user}) results = [] for fleet in user_fleets: if fleet['imo']: search_by = 'imo' q = fleet['imo'] else: search_by = 'mmsi' q = fleet['mmsi'] details = query_vessel_details(conn, search_by, q) if len(details) > 0: results.append(details[0]) return {'objects': results, 'res': RESP_RESULT.S}