Exemple #1
0
 def _reinit(self):
     self.start_time = get_pacific_time()
     self.schedules = {}
     self.errors = {}
     self.clean = False
     self.finish_time = None
     self.pid = os.getpid()
Exemple #2
0
def get_stops(schedule, name_index, station_name, sdate=None, stime=None):
    try:
        station_name = name_index[station_name]
    except KeyError:
        return NotFound(is_breaking=False)
    start_dt = parse_date_params(sdate, stime)
    start_dt = get_pacific_time(start_dt)
    stops = schedule.get_stops(station_name, start_dt)
    return {"station_name": station_name, "stops": stops}
Exemple #3
0
 def lock(self):
     if self.clean:
         cur_time = get_pacific_time()
         total_seconds = (cur_time - self.start_time).total_seconds()
         if FETCH_TIMEOUT and total_seconds > FETCH_TIMEOUT:
             self._reinit()
             self._purge()
         else:
             return False
     if not os.path.exists(self.target_dir_path):
         os.makedirs(self.target_dir_path)
     self.write_file()
     return True
Exemple #4
0
def parse_date_params(start_date, start_time):
    from datetime import datetime

    now = get_pacific_time()
    sdate, stime = now.date(), now.time()
    try:
        if len(start_date) % 2 == 1:
            start_date = "0" + start_date
        if len(start_date) == 4:
            sdate = sdate.replace(month=int(start_date[:2]), day=int(start_date[2:4]))
        elif len(start_date) == 8:
            sdate = sdate.replace(year=int(start_date[:4]), month=int(start_date[4:6]), day=int(start_date[6:8]))
    except (TypeError, ValueError):
        pass
    try:
        if len(start_time) % 2 == 1:
            start_time = "0" + start_time
        if len(start_time) == 4:
            stime = stime.replace(hour=int(start_time[:2]), minute=int(start_time[2:4]))
    except (TypeError, ValueError):
        pass
    return datetime.combine(sdate, stime)
def get_stops(schedule, name_index, station_name, sdate=None, stime=None):
    start_dt = parse_date_params(sdate, stime)
    start_dt = get_pacific_time(start_dt)
    station_name = name_index[station_name]
    stops = schedule.get_stops(station_name, start_dt)
    return {'stops': stops}
Exemple #6
0
def make_target_dirname(dt=None):
    if not dt:
        dt = get_pacific_time()
    return dt.strftime(_DATE_DIR_FORMAT)