def start_clockify_timer():
        """
        Starts a new Clockify Time Entry
        """
        # TODO add support for multiple Workspaces
        workspace = Workspace.get_all()[0]

        current_time = datetime.now().astimezone(pytz.utc)

        data = {"start": current_time.strftime("%Y-%m-%dT%H:%M:%SZ")}

        response = ClockifyApiCall(RequestTypes.POST, "workspaces/{}/time-entries".format(workspace.id), data=data)\
            .exec().json()
        return response
    def test_get_all(self, m_from_json):
        """Workspace.get_all"""
        response = MagicMock()
        self.m_clockify_api_exec.return_value = response
        response.json.return_value = [{"name": "WS1"}, {"name": "WS2"}]

        ws1 = MagicMock()
        ws2 = MagicMock()
        m_from_json.side_effect = [ws1, ws2]

        workspaces = Workspace.get_all()

        m_from_json.assert_has_calls(
            [call({"name": "WS1"}),
             call({"name": "WS2"})], any_order=True)

        self.assertEqual(len(workspaces), 2)
        self.assertTrue(ws1 in workspaces)
        self.assertTrue(ws2 in workspaces)
Example #3
0
    else:
        if commit.hexsha.startswith(args.end_commit):
            in_range = True

        if in_range:
            passed_commits.append(commit)

        if commit.hexsha.startswith(args.start_commit):
            break

# Reverse to start with the oldest commit
passed_commits = list(reversed(passed_commits))
first_commit_start = datetime.fromtimestamp(passed_commits[0].authored_date)

# Check to see if there is a currently-running Clockify timer
workspace = Workspace.get_all()[0]
user_api_call = ClockifyApiCall(RequestTypes.GET, "/user")
user = user_api_call.exec().json()
timers_api_call = ClockifyApiCall(
    RequestTypes.GET,
    f"/workspaces/{workspace.id}/user/{user['id']}/time-entries")
timers = timers_api_call.exec().json()

if len(timers) > 0:
    top_timer = timers[0]
else:
    top_timer = None
timer_running = False
if top_timer and not top_timer["timeInterval"]["end"]:
    # Timer is running
    print("Timer is running!")