timetaggerコマンドラインを使う - aktnk/til GitHub Wiki

  • Python モジュールとして提供されている timetagger_cli をインストールすることで、timetagger コマンドでデータの登録やデータの表示が可能

timetagger_cliモジュールをインストールする

なお、以下はWSL2のUbuntu20.04LTS上のPython 3.10.5で作成した仮想環境venv310を使用している

  1. pipコマンドでtimetagger_cliをインストールする
    (venv310) $ pip install timetagger_cli
    Collecting timetagger_cli
      Downloading timetagger_cli-24.7.1-py3-none-any.whl.metadata (1.6 kB)
    Collecting requests (from timetagger_cli)
      Downloading requests-2.32.3-py3-none-any.whl.metadata (4.6 kB)
    Collecting toml (from timetagger_cli)
      Downloading toml-0.10.2-py2.py3-none-any.whl.metadata (7.1 kB)
    <省略>
    Downloading urllib3-2.2.3-py3-none-any.whl (126 kB)
    Installing collected packages: urllib3, toml, idna, charset-normalizer, certifi, requests, timetagger_cli
    Successfully installed certifi-2024.8.30 charset-normalizer-3.4.0 idna-3.10 requests-2.32.3 timetagger_cli-24.7.1 toml-0.10.2 urllib3-2.2.3
    (venv310) $
    
  2. timetaggerコマンドが実行可能か確認する 正常にインストールされていれば、下記ようにusageが表示される
    (venv310) $ timetagger
    usage: timetagger [-h] [--version] {setup,app,status,show,diagnose,start,stop,add,resume} ...
    
    Track your time from the command-line, a CLI for https://timetagger.app.
    
    positional arguments:
      {setup,app,status,show,diagnose,start,stop,add,resume}
        setup               Edit the API URL and token by opening the config file in your default editor.
        app                 Open the TimeTagger app in your default browser.
        status              Get an overview of today and this week. The exact content may change.
        show                List records of the requested time frame.
        diagnose            Load all records and perform diagnostics to detect errors. Use '--fix' to fix errors.
        start               Start timer with the given description. Use '#' to create tags.
        stop                Stop any running timers.
        add                 Add already finished task.
        resume              Start a timer with the same description as the selected record.
    
    options:
      -h, --help            show this help message and exit
      --version             show program's version number and exit
    (venv310) $
    

動作させているTimeTaggerサーバに合わせて設定を行う

  1. timetagger setupコマンドを実行する 下記のようにconfig.txtが生成されるが、編集できなかった
    (venv310) $ timetagger setup
    Config file: /home/tanaka/.config/timetagger_cli/config.txt
    Will now (try to) open the config file. Just edit and save the file.
    (venv310) $ 
    
  2. config.txtを編集し、api_urlapi_tokenを動作させているTimeTaggerサーバに合わせて設定する
    (venv310) $ vi ~/.config/timetagger_cli/config.txt
    # This is the TimeTagger CLI configurationm, in toml format.
    # Clear or remove this file to reset to factory defaults.
    
    # Set the base API URL, for example:
    # - "https://timetagger.app/api/v2/"  -> default
    # - "http://localhost/timetagger/api/v2/"  -> a local server
    api_url = "http://localhost:8080/timetagger/api/v2/"
    
    # Set your API token.
    # Go to the account page, copy the token, paste it here (between the quotes).
    api_token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6InVzZXIxIiwiZXhwaXJlcyI6MzI1MDM3NDg0MDAsInNlZWQiOiI0R2FLdldjYUxFTSJ9.G21SQp-xOhIJyk6K5Pl2gvbkSdeDwAyIrlh3XLQh580"
    
  3. 設定に問題がないか動作を確認する 下記のように表示され、起動しているTimeTaggerサーバにアクセスできているがわかる
    (venv310) $ timetagger status
    
    Hours clocked this week: 1:02
    Hours clocked today: 1:02
    Running: N/A
    
    Todays records:
              Started           Stopped  Duration  Description
     2024-11-03 09:15             10:17      1:02  #mtg
    (venv310) $
    

timetaggerコマンドで登録データを表示する

  1. timetagger showコマンドを実行し、登録されているデータを表示する
    (venv310) $ timetagger show
    Start:       2024-11-03 00:00:00
    End:         2024-11-03 21:23:16.769263
    Time Period: 1 days
    Total Hours: 1:02
    
    Records:
              Started           Stopped  Duration  Description
     2024-11-03 09:15             10:17      1:02  #mtg
    (venv310) $
    
    TimeTaggerサーバで表示しているデータと同様なデータが表示されていることがわかる now_datas