def get_schedule_entries_between_locations(self, src_location, dest_location, limit=-1): """ Should pas in the string labels for the source and dest locations. """ cur = self.db_conn.cursor() sql = 'SELECT * FROM schedule_entry WHERE src_loc_id = ? AND dest_loc_id = ? ORDER BY depart_time ASC' # does this work or do we need to check if > 0? if limit: sql += ' LIMIT %d' % limit # get the actual locations d_loc = Locations.get_location_by_label(dest_location) s_loc = Locations.get_location_by_label(src_location) cur.execute(sql, s_loc.id, d_loc.id) cur.close() row = cur.fetchone() if not row: return None return ScheduleEntry(self.db_conn, row)
def fromRow(row, db_conn): locations = Locations(db_conn) schedules = Schedules(db_conn) self.parent_schedule = schedules.get_schedule_by_id(int(row['schedule_id'])) self.rowid = int(row['ROWID'], 0) self.src_loc = locations.get_location_by_id(int(row['src_loc_id'])) self.dest_loc = locations.get_location_by_id(int(row['dest_loc_id'])) self.day = int(row['day'], 10) self.arrive_time = self.ptime(row['arrive_time']) self.depart_time = self.ptime(row['depart_time'])
def get_entries_for_schedule_at_loc(self, schedule, loc): """ Should pass in a valid schedule object and the location label """ cur = self.db_conn.cursor() sql = ('SELECT * FROM schedule_entry' ' WHERE schedule_id = ?' ' AND src_loc_id = ?') src_loc = Locations.get_location_by_label(loc) cur.execute(sql, schedule.id, src_loc.id) rows = cur.fetchall() cur.close() return [ScheduleEntry(self.db_conn, row) for row in rows]
def get_schedule_entries_for_dest_loc(self, location, limit=-1): cur = self.db_conn.cursor() sql = 'SELECT * FORM schedule_entry WHERE dest_loc_id = ? ORDER BY arrive_time ASC' if limit: sql += ' LIMIT %d' % limit # get the location location = Locations.get_location_by_label(location) cur.execute(sql, location.id) cur.close() row = cur.fetchone() if not row: return None return ScheduleEntry(self.db_conn, row)