Пример #1
0
def journal(
    msg: str = Argument(None, help="The journal message to record"),
    delete: int = Option(None, help="Delete a message by id"),
    show: bool = Option(True,
                        help="display records for day/week/month/date_key"),
    period: str = Option(
        "day",
        help="The type of time period key to display messages. [day,week,"
        "month] can be combined with 'show' or 'key'.",
    ),
    key: str = KEY,
    id: int = Option(None, help="Add a journal to a specific clok record"),
    week: bool = WEEK,
    month: bool = MONTH,
    all_jobs: bool = ALL_JOBS,
):
    """Show and manage journal entries"""
    if delete is not None:
        id = delete
    if msg is not None:
        if id is not None:
            c = Clok.get_by_id(id)
            if c is not None:
                c.add_journal(msg)
            else:
                raise ValueError(f"Sorry I couldn't find that id :({id})")
        else:
            Clok.get_last_record().add_journal(msg)
    if week:
        period = "week"
    elif month:
        period = "month"

    if show:
        records = get_records_for_period(period, key, all_jobs=all_jobs)
        print(f"Printing Journal entries for the {key or period.lower()}.")
        for i in records:
            for journal in i.journal_entries:
                print(journal)

    if delete is not None:
        print(Journal.get_by_id(id))
        typer.confirm(
            f"Are you sure that you want to delete this record? ({id})?")
        Journal.delete_by_id(id)
Пример #2
0
def repair():

    for j in Journal.query().all():
        print(j.clok_id, j.time, j.entry)
        if j.entry is None or j.entry == "show":
            Journal.delete_by_id(j.id)