-
Notifications
You must be signed in to change notification settings - Fork 1
feat: add flags for get-status subcommand #37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
de16d02
99fc326
6d1a6e3
59443e8
28a318f
466e063
a9c8ab7
0ea74e7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
| """ | ||
| from __future__ import annotations | ||
|
|
||
| import calendar | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Also, when importing new modules, please add them to the corresponding |
||
| import csv | ||
| import json | ||
| import logging | ||
|
|
@@ -15,6 +16,7 @@ | |
| from getpass import getpass | ||
| from operator import itemgetter | ||
| from pathlib import Path | ||
| from typing import Optional | ||
|
|
||
| from tzlocal import get_localzone | ||
|
|
||
|
|
@@ -417,9 +419,14 @@ def get_sign_requests(self, date: str) -> dict | list: | |
| return {} | ||
|
|
||
| def get_status( | ||
| self, only_running_clock: bool = False, | ||
| ) -> tuple[timedelta, bool]: | ||
| self, only_running_clock: bool = False, period: str = "today", | ||
| ) -> tuple[timedelta, Optional[bool]]: | ||
| """Return the total amount of worked hours and current sign status.""" | ||
| # Retrieve info for the period flags, e.g., --week, --month, --year | ||
| if period != "today": | ||
| return self._get_status_period(period), None | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would rather use Another option is to return the sign-in status also for each variation of What do you think?
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's go with the
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Additionally, the (.venv) mpalacin@bsc-84885021:~/GitHub/personal_projects/woffu-client$ woffu-cli get-status
[2025-10-17 10:04:53] INFO woffu_api_client: Hours worked today: 00:42:22
[2025-10-17 10:04:53] INFO woffu_api_client: You're currently signed in.
(.venv) mpalacin@bsc-84885021:~/GitHub/personal_projects/woffu-client$ woffu-cli get-status --week
[2025-10-17 10:05:02] INFO woffu_api_client: Hours worked this week: 14:25
❌ Error retrieving status: not enough values to unpack (expected 2, got 1)Please try to secure this. |
||
|
|
||
| # Get current sign-in status and worked hours for today | ||
| signs_in_day = self.get(url=f"{self._woffu_api_url}/api/signs").json() | ||
|
|
||
| # Initialize a timer and the running clock boolean | ||
|
|
@@ -487,6 +494,41 @@ def get_status( | |
| ) | ||
| return total_time, running_clock | ||
|
|
||
| def _get_status_period(self, period: str) -> timedelta: | ||
| today = datetime.now().date() | ||
| match period: | ||
| case "week": | ||
| from_date = today - timedelta(days=today.weekday()) | ||
| to_date = from_date + timedelta(days=6) | ||
| case "month": | ||
| from_date = today.replace(day=1) | ||
| last_day = calendar.monthrange(today.year, today.month)[1] | ||
| to_date = today.replace(day=last_day) | ||
| case "year": | ||
| from_date = today.replace(month=1, day=1) | ||
| to_date = today.replace(month=12, day=31) | ||
|
|
||
| diary_json = self.get( | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here you're calling the same HTTP endpoint as in |
||
| url=f"https://{self._domain}/api/svc/core/diariesquery/users/\ | ||
| {self._user_id}/diaries/summary/presence", | ||
| params={ | ||
| "fromDate": from_date, | ||
| "toDate": to_date, | ||
| "showHidden": False, | ||
| }, | ||
| ).json() | ||
|
|
||
| h, m = map(int, diary_json["totalWorkedTimeFormatted"]["values"]) | ||
| logger.info( | ||
| "Hours worked this {}: {:02d}:{:02d}".format(period, h, m), | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For consistency's sake with the default results, we should use the same time format, including hours, minutes and seconds. This way we ease the job of any external parser that might want to extract this value: "Hours worked today: {:02d}:{:02d}:{:02d}".format(
int(hours), int(minutes), int(seconds),
), |
||
| ) | ||
| total_time = timedelta(hours=h, minutes=m) | ||
|
|
||
| h, m = diary_json["totalWorkingTimeFormatted"]["values"] | ||
| logger.info(f"Hours scheduled for this {period}: {h}:{m}") | ||
|
|
||
| return total_time | ||
|
|
||
| def sign(self, type: str = "") -> HTTPResponse | None: | ||
| """ | ||
| Sign in/out on Woffu. | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be good to also define a subparser argument for
--todayeven though it's the default value, so users using some kind of automated script to invokewoffu-clican easily swap between any of the options and not worry about having to leave it empty. What do you think?