Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
__pycache__/
logs/fuckWoffu.log
secrets.json
config/secrets.json
15 changes: 15 additions & 0 deletions .vscode/launch.json

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove this file, I don't want VS code specific configurations inside the repo

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Python Debugger: Current File with Arguments",
"type": "debugpy",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"args": [
"--test"
]
}
]
}
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,11 @@ Directly by composer:
```sh
docker compose up
```

# Testing the Connection

To verify the connection to Woffu without registering any inputs, you can use the `--test` argument. This operation ensures that your secrets are properly configured without making any changes in Woffu.

```bash
python3 fuckWoffu.py --test
```
35 changes: 30 additions & 5 deletions fuckWoffu.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import argparse
import sched
import time
import logging
Expand All @@ -15,7 +16,9 @@
Every 60 seconds I check my enter/leave time and execute request
'''
TIME_TO_CHECK = 60

ERROR_MESSAGE = 'Error maybe something should be done ¯\(ツ)/¯ '
SO_FAR_SO_GOOD_MESSAGE = 'So far, so good!'
ERROR_TOKEN = '¯\(ツ)/¯'

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️


def main(scheduler):
email, password, sign_times, company_name = get_json_data()
Expand All @@ -28,15 +31,37 @@ def main(scheduler):
notify('Sign in/out succesfully')
logging.warning('Sign in succesfully')
else:
logging.error('Error maybe something should be done ¯\(ツ)/¯ ')
logging.error()
else:
logging.warning('I am on holiday, no check in')

# Restart the timer
scheduler.enter(TIME_TO_CHECK, 1, main, (scheduler,))

def testConection():
email, password, sign_times, company_name = get_json_data()
try:
sign_in_app = SignInWoffu(email, password, company_name)
if sign_in_app.token == ERROR_TOKEN:
logging.error(ERROR_MESSAGE)
print(ERROR_MESSAGE)
else:
logging.info(SO_FAR_SO_GOOD_MESSAGE)
print(SO_FAR_SO_GOOD_MESSAGE)
except Exception as e:
message = f'An error occurred during sign-in: {e}'
logging.error(message)
print(message)


if __name__ == "__main__":
scheduler = sched.scheduler(time.time, time.sleep)
scheduler.enter(TIME_TO_CHECK, 1, main, (scheduler,))
scheduler.run()
parser = argparse.ArgumentParser(description='Woffu Auto Check-In script')
parser.add_argument('--test', help='Optional test parameter', action='store_true')
args = parser.parse_args()

if args.test:
testConection()
else:
scheduler = sched.scheduler(time.time, time.sleep)
scheduler.enter(TIME_TO_CHECK, 1, main, (scheduler,))
scheduler.run()
27 changes: 17 additions & 10 deletions src/SignInWoffu.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,27 @@ def _get_pto_holiday(self):
return holidays_list

def _calculate_vacation_range(self, day, holidays_list):
requested_days = int(day['RequestedFormatted']['Values'][0])
first_day = datetime.strptime(
day['StartDate'], '%Y-%m-%dT%H:%M:%S.%f')
if requested_days == 1:
holidays_list.append(first_day)
return
requested_days = float(day['RequestedFormatted']['Values'][0])
first_day = datetime.strptime(day['StartDate'], '%Y-%m-%dT%H:%M:%S.%f')

# Detect vacation range:
last_day = datetime.strptime(
day['EndDate'], '%Y-%m-%dT%H:%M:%S.%f')
# Append the first day
holidays_list.append(first_day)

# Calculate the entire vacation range
last_day = datetime.strptime(day['EndDate'], '%Y-%m-%dT%H:%M:%S.%f')
time_difference = (last_day - first_day).days + 1
for d in range(time_difference):

# Append all full days
for d in range(1, int(requested_days)):
annother_day = first_day + timedelta(days=d)
holidays_list.append(annother_day)

# Handle fractional day at the end
if requested_days % 1 != 0:
partial_day = first_day + timedelta(days=int(requested_days))
holidays_list.append(partial_day)

return holidays_list

def _get_token(self, email, password):
url = "https://" + self.company_name + ".woffu.com/token"
Expand Down