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
49 changes: 23 additions & 26 deletions hackmeter/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,22 +102,20 @@ def check_day_reporting(self, day: datetime.date):
f'enddate={end_day.strftime(DATE_FORMAT)}&fillblanks=true',
headers=self.headers
)
if response.status_code == 200:
logging.info(f'Day report obtained for {day.isoformat()}')
day_report = json.loads(response.content.decode())
for report in day_report:
if response.status_code != 200:
raise Exception(f'Day {day.isoformat()} problem.')
logging.info(f'Day report obtained for {day.isoformat()}')
day_report = json.loads(response.content.decode())
for report in day_report:

# TODO in the future calculate the reported time and optimize the reports
date_reported = report['date']
date_reported = f'{date_reported[6:]}-{date_reported[3:5]}-{date_reported[:2]}'
if report.get('tasks') and date_reported not in self.reported_days:
self.reported_days.append(date_reported)
logging.info(f'Day {date_reported} was previously reported')
# TODO in the future calculate the reported time and optimize the reports
date_reported = report['date']
date_reported = f'{date_reported[6:]}-{date_reported[3:5]}-{date_reported[:2]}'
if report.get('tasks') and date_reported not in self.reported_days:
self.reported_days.append(date_reported)
logging.info(f'Day {date_reported} was previously reported')

self.reported_days = list(set(self.reported_days))

else:
raise Exception(f'Day {day.isoformat()} problem.')
self.reported_days = list(set(self.reported_days))
Comment on lines -105 to +118
Copy link
Author

Choose a reason for hiding this comment

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

Function WorkmeterClient.check_day_reporting refactored with the following changes:


def get_reported_days(
self,
Expand All @@ -136,19 +134,18 @@ def get_expected_calendar(
f'{self.base_url}/api/Calendar/{year}/User/{self.userid}',
headers=self.headers
)
if response.status_code == 200:
logging.info(f'Calendar obtained for year {year}')
calendar = json.loads(response.content.decode())
for day in calendar:
if (
(expected_day := day['date'][:10]) and
until.isoformat() >= expected_day >= self.start_day.isoformat() and
expected_day not in self.holidays and
(expected_minutes := day.get('expected'))
):
self.expected_days[day['date'][:10]] = expected_minutes
else:
if response.status_code != 200:
raise Exception(f'Error obtaining calendar for year "{year}".')
logging.info(f'Calendar obtained for year {year}')
calendar = json.loads(response.content.decode())
for day in calendar:
if (
(expected_day := day['date'][:10]) and
until.isoformat() >= expected_day >= self.start_day.isoformat() and
expected_day not in self.holidays and
(expected_minutes := day.get('expected'))
):
self.expected_days[day['date'][:10]] = expected_minutes
Comment on lines -139 to +148
Copy link
Author

Choose a reason for hiding this comment

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

Function WorkmeterClient.get_expected_calendar refactored with the following changes:


def report(self):
logging.info('Reporting all ')
Expand Down
2 changes: 1 addition & 1 deletion hackmeter/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def test_login(self):
mock_post.return_value = response
client.login(username=self.username, password=self.password)
self.assertEqual(client.token, 'test_token')
self.assertEqual(client.headers['Authorization'], f'Bearer test_token')
self.assertEqual(client.headers['Authorization'], 'Bearer test_token')
Copy link
Author

Choose a reason for hiding this comment

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

Function ClientTest.test_login refactored with the following changes:


def test_login_status_code_not_200_raise_exception(self):
client = WorkmeterClient(
Expand Down