Skip to content

Commit

Permalink
Update to use new API, linting, cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mcantelon committed Dec 6, 2023
1 parent db859c9 commit afcb114
Show file tree
Hide file tree
Showing 18 changed files with 694 additions and 556 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
name: "Test"
on:
pull_request:
push:
branches:
- "main"
jobs:
lint:
name: "Lint"
runs-on: "ubuntu-22.04"
steps:
- name: "Check out repository"
uses: "actions/checkout@v3"
- name: "Set up Python"
uses: "actions/setup-python@v3"
with:
python-version: "3.8"
- name: "Install tox"
run: |
python -m pip install --upgrade pip
pip install tox
- name: "Run tox"
run: |
tox -e linting
11 changes: 11 additions & 0 deletions .markdownlint.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"default": true,
"MD010": { // Presence of hard tabs
"code_blocks": false // Don't check code blocks
},
"MD013": { // Limit line lengths
"code_blocks": false, // Don't check code blocks
"tables": false // Don't check table Markdown
},
"MD041": false // Disable: first line in a file should be a top-level heading
}
23 changes: 23 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
repos:
- repo: https://github.com/ambv/black
rev: 18.9b0
hooks:
- id: black
args: [--safe, --quiet]
language_version: python3
- repo: https://github.com/PyCQA/flake8
rev: 6.1.0
hooks:
- id: flake8
language_version: python3
additional_dependencies: ['flake8-builtins==2.2.0']
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
language_version: python3
- repo: https://github.com/igorshubovych/markdownlint-cli
rev: v0.37.0
hooks:
- id: markdownlint
args: ["--config", ".markdownlint.jsonc"]
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include requirements/base.txt
120 changes: 22 additions & 98 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ configuration`) to rapidly create time entries. For example if you regularly
have a 15 minute scrum meeting you could create a "scrum" time entry template
that allows you to add a time entry like this:

$ ./cft +scrum
./cft +scrum


Known issues
------------
## Known issues

Clockify's API requires that all important details about a time entry be
provided when making a change to a time entry. Because of this `cft`, when
Expand All @@ -28,22 +26,18 @@ changed. This will likely be added in the future.

Tested with Python 2.7 and 3. Will need to be tweaked to handle Unicode.


Installation
------------
## Installation

Install via PyPi:

$ pip install clockifytool
pip install clockifytool

...Or clone this repo, change into the repo directory, then enter the following
command:

$ pip install -r requirements.txt

pip install -r requirements/base.txt

Basic Configuration
-------------------
## Basic Configuration

To use `cft` you'll need to, in the Clockify web UI, click the "GENERATE"
button on the "Personal settings" page to generate an API key. You'll then need
Expand Down Expand Up @@ -76,14 +70,11 @@ Read on to learn about the basic functionality of `cft` and, once you've got
the hang of things, check out `Advanced Configuration` to learn how you can
save time when entering new time entries.


Commands
--------
## Commands

Clockify Tool allows you to list, create and delete Clockify time entries. You
can also list projects, project tasks, and workspaces to find out their IDs.


### Listing time entries in a period of time

Help for the list command:
Expand Down Expand Up @@ -119,7 +110,7 @@ Help for the list command:

Example list of today's time entries:

$ ./cft
./cft

Here's example output:

Expand All @@ -146,7 +137,7 @@ project of any entry that is associated with a task rather than a project.

Here's an example of listing yesterday's time entries:

$ ./cft list yesterday
./cft list yesterday

Yesterday is one time period of a number of available time periods.

Expand All @@ -156,13 +147,12 @@ for "yesterday" is "y", for example.
`cft` commands like "list" can have one letter abbreviations. So if you
wanted to list yesterday's time entries you could enter:

$ ./cft l y
./cft l y

Another time saver: if you enter a time period, instead of a command, you'll
get a list of entries in the time period:

$ ./cft y

./cft y

### List time entries in an arbitrary date range

Expand All @@ -174,16 +164,15 @@ one that's omitted they will default to today's date.

Example list of time entries in an arbitary date range:

$ ./cft l -s 2019-03-06 --e 2019-03-09
./cft l -s 2019-03-06 --e 2019-03-09

The `-` or `+` operators, as a prefix to a integeter represeting a number of
days, can also be used to indicate a relative date.

For example, if one wanted to list time entries created five days ago to the
present day then one could use this command:

$ ./cft l -s -5

./cft l -s -5

### List projects

Expand All @@ -196,7 +185,6 @@ For example:
* Email [5cdb08621080ec2d4a8e707e]
* Meetings [5cdb08ead278ae206156ae6f]


### Project details

The `project` (or `pd`) command is used to display details about a project,
Expand All @@ -211,7 +199,6 @@ For example:
Tasks:
* Support [5d8bff9dad3d0047ca62e3fd]


### Task details

The `task` (or `td`) command is used to display details about a task.
Expand All @@ -222,7 +209,6 @@ For example:
Name: Support
Project ID: ed5c600955e74cce9648cd91


### Creating a time entry

The `new` (or `n`) command is used to create a new time entry. The number of
Expand All @@ -249,95 +235,39 @@ Help for the new command:

Here's an example (in which `5cb772f3f15c9857ee275d00` is the project ID:

$ ./cft new 5cb772f3f15c9857ee275d00 --comments="Checking email." --hours=.25
./cft new 5cb772f3f15c9857ee275d00 --comments="Checking email." --hours=.25

Here's the same example in a briefer form.

$ ./cft n 5cb772f3f15c9857ee275d00 -c "Checking email." -t .25
./cft n 5cb772f3f15c9857ee275d00 -c "Checking email." -t .25

When specifying a date, the `+` or `-` operators are relative to the current
date. If you create a time entry today that should be dated as yesteray you
could update it with `-1` as the date to fix.

For example:

$ ./cft n 5cb772f3f15c9857ee275d00 -c "Checking email." -t .25 -d -1
./cft n 5cb772f3f15c9857ee275d00 -c "Checking email." -t .25 -d -1

If specifying a start time, using the `--start`/`-s` optional argument, the
time should be specified in 24 hour time format.

For example:

$ ./cft n 5cb772f3f15c9857ee275d00 -c "Checking email." -t .25 -s 13:15
./cft n 5cb772f3f15c9857ee275d00 -c "Checking email." -t .25 -s 13:15

Note that when adding a time entry the current time will be used as the start
time unless a date and/or start time are specified. If a date is specified, but
a start time isn't, then the start time will be midnight. If a start time is
specified, however, then the specified start time will be used.


### Updating a time entry

The `update` (or `u`) command is used to update an existing time entry.

Help for the update command:

$ ./cft update -h
usage: cft update [-h] [-c comments: required for new time entries]
[-t hours spent: required for new time entries] [-d date]
[-b] [-a append: append text to comments] [-u]
entry ID

positional arguments:
entry ID ID of time entry: required

optional arguments:
-h, --help show this help message and exit
-c comments: required for new time entries, --comments comments: required for new time entries
-t hours spent: required for new time entries, --hours hours spent: required for new time entries
-d date, --date date defaults to today
-b, --billable
-a append: append text to comments, --append append: append text to comments
-u, --unbillable

Here's an example (in which `5ce54a35a02987296634c98a` is the time entry's ID:

$ ./cft update 5ce54a35a02987296634c98a --comments="Changed tires." --hours=1.5

Comments can be amended, rather than replaced, using the `--append` option.

For example:

$ ./cft u 5ce54a35a02987296634c98a -a "I also fixed the flux capacitor."

When updating hours worked, the `+` or `-` operators can be used to increment
or decrement the entry's current hours worked value.

For example:

$ ./cft u 5ce54a35a02987296634c98a -t +.25

When adjusting a date, the `+` or `-` operators are relative to the current
date. If you added something today that should be dated as yesteray you could
update it with `-1` as the date to fix.

For example:

$ ./cft u 5ce54a35a02987296634c98a -d -1

Note: make sure you read the intro to this README file so you know that there
can be issues with updating time entries if you use both Clockify's web UI and
`cft`.


### Deleting a time entry

The `delete` (or `d`) command is used to delete a time entry.

Here's an example (in which `5cd64137b079870300a9c9e0` is the time entry ID:

$ ./cft delete 5cd64137b079870300a9c9e0

./cft delete 5cd64137b079870300a9c9e0

### List workspaces

Expand All @@ -349,16 +279,13 @@ For example:
$ ./cft workspaces
* Client-Project-Task Workspace [4c31a29da059321c02e301e0]


### Cache status/flushing

You probably won't need to use this, but it exists. The `cache` command is used
to display how many time entries have been cached. The `--flush` (or `-f`) flag
can be used to delete all cached time entries.


Advanced configuration
----------------------
## Advanced configuration

You can save time entering time entries by using advanced configuration.

Expand All @@ -376,7 +303,6 @@ Example:
meeting:
id: meet


### Project time entry templates

In addition to using an alias to specify a project, or project task, ID, you
Expand All @@ -402,12 +328,10 @@ overrride the --time command-line option.

Example:

$ ./cft n scrum -t .5

./cft n scrum -t .5

Shortcuts and abbreviations
---------------------------
### Shortcuts and abbreviations

Example of quick addition of a time entry using a template:

$ ./cft +scrum
./cft +scrum
21 changes: 10 additions & 11 deletions bin/cft
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
#!/usr/bin/env python

from __future__ import print_function
import os
import sys

sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), os.pardir))

from clockifytool import __version__ as VERSION
from clockifytool import app, cli, commands
from clockifytool.api import ClockifyApi
from clockifytool import app, cli, commands, __version__ as VERSION


# Parse CLI arguments
parser = cli.arg_parser()
args = parser.parse_args(cli.preprocess_argv())

# Display version if need be (config might not exist yet)
if args.command == 'version':
print('clockifytool version {}'.format(VERSION))
if args.command == "version":
print("clockifytool version {}".format(VERSION))
sys.exit(0)

# Load configuration
Expand All @@ -27,21 +26,21 @@ except Exception as e:
sys.exit(1)

# Authenticate
clockify = ClockifyApi(config['api key'])
clockify = ClockifyApi(config["api key"])

# Display available workspaces or set workspace
if 'workspace' not in config:
config_path = os.path.join(os.path.expanduser('~'), config['filename'])
if "workspace" not in config:
config_path = os.path.join(os.path.expanduser("~"), config["filename"])
print('Please set workspace ID as "workspace" in {}.'.format(config_path))
print("\nAvailable workspaces:")
commands.list_workspaces(None, None, {'clockify': clockify})
commands.list_workspaces(None, None, {"clockify": clockify})
sys.exit(1)
else:
clockify.set_workspace(config['workspace'])
clockify.set_workspace(config["workspace"])

# Validate CLI arguments and execute command
args = cli.validate_args(parser, args, config)
command_function = getattr(commands, args.func)

app_data = {'clockify': clockify}
app_data = {"clockify": clockify}
command_function(args, config, app_data)
Loading

0 comments on commit afcb114

Please sign in to comment.