示例#1
0
def build_THSR():
    """
    高鐵提供近45天每日時刻表
    """
    session = Session()
    today = datetime.now().date()
    for i in range(45):
        d = today + timedelta(i)
        print("Start building THSR DATABASE on {0}".format(
            convert_date_to_string(d)))
        resp = build_THSR_database_by_date(d, session)
        print("Finish THSR DATABASE on {0}, result={1}".format(
            convert_date_to_string(d), resp.message))
    session.close()
示例#2
0
def build_TRA():
    """
    台鐵提供近60天每日時刻表
    Building strategy for TRA:
    1. update tomorrow's data on every midnight anyway
    2. make sure that data within a month has existed
    """
    session = Session()
    today = datetime.now().date()
    for i in range(60):
        d = today + timedelta(i)
        print("Start building TRA DATABASE on {0}".format(
            convert_date_to_string(d)))
        resp = build_TRA_database_by_date(d, session)
        print("Finish TRA DATABASE on {0}, result={1}".format(
            convert_date_to_string(d), resp.message))
    session.close()
示例#3
0
 def search_by_date(self):
     """
     search users' tasks by date
     """
     utils.clear_screen()
     print("Enter the date:\n")
     date = utils.get_date()
     date = utils.convert_date_to_string(date)
     return list(filter(lambda task: task.date == date, self.tasks))
def request_TRA_all_train_timetable_by_date(date_input):
    date_string = convert_date_to_string(date_input)
    url = URL_FOR_ALL_TRA_TRAIN_NO_AND_TIMETABLE.format(date_string)
    try:
        resp = request_MOTC(url)
    except Exception as e:
        traceback.print_exc(file=sys.stdout)
        return ResponseMessage(1)
    if not resp:
        return ResponseMessage(2)
    elif "message" in resp:
        return ResponseMessage(10, resp["message"])
    return resp
def request_THSR_all_train_timetable(date_input):
    """
    :return: a list of RailDailyTimetable
    """
    date_string = convert_date_to_string(date_input)
    url = URL_FOR_ALL_THSR_TRAIN_NO_AND_TIMETABLE.format(date_string)
    try:
        resp = request_MOTC(url)
    except:
        traceback.print_exc(file=sys.stdout)
        return ResponseMessage(1)
    if not resp:
        return ResponseMessage(2)
    elif "message" in resp:
        return ResponseMessage(10, resp["message"])
    return resp
示例#6
0
 def create_users_task(self):
     """
     Get user input and create users task
     """
     utils.clear_screen()
     print("Date of the task")
     date = utils.get_date()
     date = utils.convert_date_to_string(date)
     utils.clear_screen()
     title = input("Title of the task: ")
     utils.clear_screen()
     time_spent = utils.get_time_spent()
     utils.clear_screen()
     notes = input("Notes (Optional, you can leave this empty): ")
     utils.clear_screen()
     self.add_task(date, title, time_spent, notes)
     print("Task successfully logged.\n")
示例#7
0
 def edit_task(self, task):
     """
     Edit and update selected task
     """
     while True:
         print("*" * 25)
         print("Editing task:")
         print("*" * 25)
         print(task)
         print("*" * 25)
         print("New Values:")
         print("*" * 25)
         print("Date of the task")
         date = utils.get_date()
         date = utils.convert_date_to_string(date)
         title = input("Title of the task: ")
         time_spent = utils.get_time_spent()
         notes = input("Notes (Optional, you can leave this empty): ")
         task.date = date
         task.title = title
         task.time_spent = time_spent
         task.notes = notes
         print("Task updated")
         break
示例#8
0
 def getDeadline(self):
     """ """
     return utils.convert_date_to_string(self.deadline)