├── .github └── workflows │ └── package.yml ├── .gitignore ├── LICENSE ├── MANIFEST.in ├── README.md ├── img ├── screenshot-macos.png └── screenshot-ubuntu.png ├── setup.py └── tomato.py /.github/workflows/package.yml: -------------------------------------------------------------------------------- 1 | name: Publish 📦 to PyPI 2 | 3 | on: push 4 | 5 | jobs: 6 | build: 7 | name: Build distribution 📦 8 | runs-on: ubuntu-latest 9 | 10 | steps: 11 | - uses: actions/checkout@v4 12 | - name: Set up Python 13 | uses: actions/setup-python@v4 14 | with: 15 | python-version: "3.x" 16 | 17 | - name: Install pypa/build 18 | run: >- 19 | python3 -m 20 | pip install 21 | build 22 | --user 23 | - name: Build a binary wheel and a source tarball 24 | run: python3 -m build 25 | - name: Store the distribution packages 26 | uses: actions/upload-artifact@v3 27 | with: 28 | name: python-package-distributions 29 | path: dist/ 30 | 31 | publish-to-pypi: 32 | name: >- 33 | Publish 📦 to PyPI 34 | if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes 35 | needs: 36 | - build 37 | runs-on: ubuntu-latest 38 | environment: 39 | name: pypi 40 | url: https://pypi.org/p/tomato-clock 41 | permissions: 42 | id-token: write # IMPORTANT: mandatory for trusted publishing 43 | steps: 44 | - name: Download all the dists 45 | uses: actions/download-artifact@v4.1.7 46 | with: 47 | name: python-package-distributions 48 | path: dist/ 49 | - name: Publish distribution 📦 to PyPI 50 | uses: pypa/gh-action-pypi-publish@release/v1 51 | 52 | github-release: 53 | name: >- 54 | Sign 📦 with Sigstore 55 | and upload them to GitHub Release 56 | needs: 57 | - publish-to-pypi 58 | runs-on: ubuntu-latest 59 | 60 | permissions: 61 | contents: write # IMPORTANT: mandatory for making GitHub Releases 62 | id-token: write # IMPORTANT: mandatory for sigstore 63 | 64 | steps: 65 | - name: Download all the dists 66 | uses: actions/download-artifact@v4.1.7 67 | with: 68 | name: python-package-distributions 69 | path: dist/ 70 | - name: Sign the dists with Sigstore 71 | uses: sigstore/gh-action-sigstore-python@v1.2.3 72 | with: 73 | inputs: >- 74 | ./dist/*.tar.gz 75 | ./dist/*.whl 76 | - name: Create GitHub Release 77 | env: 78 | GITHUB_TOKEN: ${{ github.token }} 79 | run: >- 80 | gh release create 81 | '${{ github.ref_name }}' 82 | --repo '${{ github.repository }}' 83 | --notes "" 84 | - name: Upload artifact signatures to GitHub Release 85 | env: 86 | GITHUB_TOKEN: ${{ github.token }} 87 | # Upload to GitHub Release using the `gh` CLI. 88 | # `dist/` contains the built packages, and the 89 | # sigstore-produced signatures and certificates. 90 | run: >- 91 | gh release upload 92 | '${{ github.ref_name }}' dist/** 93 | --repo '${{ github.repository }}' 94 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by .ignore support plugin (hsz.mobi) 2 | ### Python template 3 | # Byte-compiled / optimized / DLL files 4 | __pycache__/ 5 | *.py[cod] 6 | *$py.class 7 | 8 | # C extensions 9 | *.so 10 | 11 | # Distribution / packaging 12 | .Python 13 | build/ 14 | develop-eggs/ 15 | dist/ 16 | downloads/ 17 | eggs/ 18 | .eggs/ 19 | lib/ 20 | lib64/ 21 | parts/ 22 | sdist/ 23 | var/ 24 | wheels/ 25 | pip-wheel-metadata/ 26 | share/python-wheels/ 27 | *.egg-info/ 28 | .installed.cfg 29 | *.egg 30 | MANIFEST 31 | 32 | # PyInstaller 33 | # Usually these files are written by a python script from a template 34 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 35 | *.manifest 36 | *.spec 37 | 38 | # Installer logs 39 | pip-log.txt 40 | pip-delete-this-directory.txt 41 | 42 | # Unit test / coverage reports 43 | htmlcov/ 44 | .tox/ 45 | .nox/ 46 | .coverage 47 | .coverage.* 48 | .cache 49 | nosetests.xml 50 | coverage.xml 51 | *.cover 52 | .hypothesis/ 53 | .pytest_cache/ 54 | 55 | # Translations 56 | *.mo 57 | *.pot 58 | 59 | # Django stuff: 60 | *.log 61 | local_settings.py 62 | db.sqlite3 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | target/ 76 | 77 | # Jupyter Notebook 78 | .ipynb_checkpoints 79 | 80 | # IPython 81 | profile_default/ 82 | ipython_config.py 83 | 84 | # pyenv 85 | .python-version 86 | 87 | # pipenv 88 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 89 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 90 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 91 | # install all needed dependencies. 92 | #Pipfile.lock 93 | 94 | # celery beat schedule file 95 | celerybeat-schedule 96 | 97 | # SageMath parsed files 98 | *.sage.py 99 | 100 | # Environments 101 | .env 102 | .venv 103 | env/ 104 | venv/ 105 | ENV/ 106 | env.bak/ 107 | venv.bak/ 108 | 109 | # Spyder project settings 110 | .spyderproject 111 | .spyproject 112 | 113 | # Rope project settings 114 | .ropeproject 115 | 116 | # mkdocs documentation 117 | /site 118 | 119 | # mypy 120 | .mypy_cache/ 121 | .dmypy.json 122 | dmypy.json 123 | 124 | # Pyre type checker 125 | .pyre/ 126 | .DS_Store 127 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Bruce Lee 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include LICENSE 2 | include README.md 3 | include *.py -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 🍅 Tomato Clock (Python) 2 | 3 | [![Publish to PyPI](https://github.com/coolcode/tomato-clock/actions/workflows/package.yml/badge.svg)](https://github.com/coolcode/tomato-clock/actions/workflows/package.yml) 4 | [![PyPI tomato-clock](https://badge.fury.io/py/tomato-clock.svg)](https://pypi.python.org/pypi/tomato-clock/) 5 | 6 | Tomato Clock is a straightforward command-line Pomodoro application. 7 | 8 | - [Pomodoro Technique](https://en.wikipedia.org/wiki/Pomodoro_Technique) 9 | - [番茄工作法](https://zh.wikipedia.org/zh-cn/%E7%95%AA%E8%8C%84%E5%B7%A5%E4%BD%9C%E6%B3%95) 10 | - [Tomato Clock (Rust)](https://github.com/coolcode/tomato-clock-rs) 11 | 12 | ## Installation 13 | 14 | [Install python](https://www.python.org) 15 | 16 | - Install via pip: 17 | 18 | ```sh 19 | pip install tomato-clock 20 | ``` 21 | 22 | - Install via source code: 23 | 24 | ```sh 25 | git clone https://github.com/coolcode/tomato-clock.git 26 | cd tomato-clock 27 | chmod +x tomato.py 28 | ``` 29 | 30 | ## How to use 31 | 32 | - if you install via pip 33 | 34 | ```sh 35 | tomato # start a 25 minutes tomato clock + 5 minutes break 36 | tomato -t # start a 25 minutes tomato clock 37 | tomato -t # start a minutes tomato clock 38 | tomato -b # take a 5 minutes break 39 | tomato -b # take a minutes break 40 | tomato -h # help 41 | ``` 42 | 43 | - if you install via source code 44 | 45 | ```sh 46 | ./tomato.py # start a 25 minutes tomato clock + 5 minutes break 47 | ./tomato.py -t # start a 25 minutes tomato clock 48 | ./tomato.py -t # start a minutes tomato clock 49 | ./tomato.py -b # take a 5 minutes break 50 | ./tomato.py -b # take a minutes break 51 | ./tomato.py -h # help 52 | ``` 53 | 54 | ## Terminal Output 55 | 56 | ```sh 57 | 🍅 tomato 25 minutes. Ctrl+C to exit 58 | 🍅🍅---------------------------------------------- [8%] 23:04 ⏰ 59 | ``` 60 | 61 | ## Desktop Notification 62 | 63 | - MacOS 64 | 65 | ```sh 66 | brew install terminal-notifier 67 | ``` 68 | 69 | `terminal-notifier` actually is a cross-platform desktop notifier, please refer to ➜ [terminal-notifier](https://github.com/julienXX/terminal-notifier#download) 70 | 71 | terminal-notifier 72 | 73 | - Ubuntu 74 | 75 | `notify-send` 76 | 77 | ubuntu-notification 78 | 79 | 80 | ## Voice Notifications 81 | 82 | Tomato Clock uses `say`(text-to-speech) for voice notifications. 83 | 84 | - MacOS 85 | 86 | MacOS already has `say`. see [here](https://ss64.com/osx/say.html) or [more detail](https://gist.github.com/mculp/4b95752e25c456d425c6) 87 | 88 | - Ubuntu 89 | 90 | See this link: [say](http://manpages.ubuntu.com/manpages/trusty/man1/say.1.html) 91 | 92 | ```sh 93 | sudo apt-get install gnustep-gui-runtime 94 | ``` 95 | 96 | - Windows 97 | 98 | Check this one: https://github.com/SeanBracksDev/tomato-clock 99 | -------------------------------------------------------------------------------- /img/screenshot-macos.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coolcode/tomato-clock/82840cffe55f3025072ab7f02e3d77d365e15a25/img/screenshot-macos.png -------------------------------------------------------------------------------- /img/screenshot-ubuntu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coolcode/tomato-clock/82840cffe55f3025072ab7f02e3d77d365e15a25/img/screenshot-ubuntu.png -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from setuptools import setup, find_packages 4 | from os import path 5 | 6 | this_directory = path.abspath(path.dirname(__file__)) 7 | with open(path.join(this_directory, "README.md"), encoding="utf-8") as f: 8 | long_description = f.read() 9 | 10 | description = "Tomato Clock is a straightforward command-line Pomodoro application." 11 | version = "0.1.2" 12 | 13 | setup( 14 | name="tomato-clock", 15 | version=version, 16 | author="Bruce Lee", 17 | author_email="bruce.meerkat@gmail.com", 18 | description=description, 19 | long_description=long_description, 20 | long_description_content_type='text/markdown', 21 | license="MIT", 22 | keywords="pomodoro tomato tomato-timer terminal terminal-app pomodoro-timer", 23 | url="https://github.com/coolcode/tomato-clock", 24 | classifiers=['Intended Audience :: Science/Research', 25 | 'Intended Audience :: Developers', 26 | 'License :: OSI Approved :: MIT License', 27 | "Programming Language :: Python", 28 | 'Topic :: Software Development', 29 | 'Topic :: Scientific/Engineering', 30 | 'Operating System :: Microsoft :: Windows', 31 | 'Operating System :: POSIX', 32 | 'Operating System :: Unix', 33 | 'Operating System :: MacOS'], 34 | platforms='any', 35 | include_package_data=True, 36 | package_data={"": ["*.md"]}, 37 | packages=find_packages(), 38 | entry_points={"console_scripts": ["tomato = tomato:main"]}, 39 | setup_requires=["wheel"], 40 | scripts=['tomato.py'] 41 | ) 42 | -------------------------------------------------------------------------------- /tomato.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | 4 | # Pomodoro 番茄工作法 https://en.wikipedia.org/wiki/Pomodoro_Technique 5 | # ====== 🍅 Tomato Clock ======= 6 | # ./tomato.py # start a 25 minutes tomato clock + 5 minutes break 7 | # ./tomato.py -t # start a 25 minutes tomato clock 8 | # ./tomato.py -t # start a minutes tomato clock 9 | # ./tomato.py -b # take a 5 minutes break 10 | # ./tomato.py -b # take a minutes break 11 | # ./tomato.py -h # help 12 | 13 | 14 | import sys 15 | import time 16 | import subprocess 17 | 18 | WORK_MINUTES = 25 19 | BREAK_MINUTES = 5 20 | 21 | 22 | def main(): 23 | try: 24 | if len(sys.argv) <= 1: 25 | print(f'🍅 tomato {WORK_MINUTES} minutes. Ctrl+C to exit') 26 | tomato(WORK_MINUTES, 'It is time to take a break') 27 | print(f'🛀 break {BREAK_MINUTES} minutes. Ctrl+C to exit') 28 | tomato(BREAK_MINUTES, 'It is time to work') 29 | 30 | elif sys.argv[1] == '-t': 31 | minutes = int(sys.argv[2]) if len(sys.argv) > 2 else WORK_MINUTES 32 | print(f'🍅 tomato {minutes} minutes. Ctrl+C to exit') 33 | tomato(minutes, 'It is time to take a break') 34 | 35 | elif sys.argv[1] == '-b': 36 | minutes = int(sys.argv[2]) if len(sys.argv) > 2 else BREAK_MINUTES 37 | print(f'🛀 break {minutes} minutes. Ctrl+C to exit') 38 | tomato(minutes, 'It is time to work') 39 | 40 | elif sys.argv[1] == '-h': 41 | help() 42 | 43 | else: 44 | help() 45 | 46 | except KeyboardInterrupt: 47 | print('\n👋 goodbye') 48 | except Exception as ex: 49 | print(ex) 50 | exit(1) 51 | 52 | 53 | def tomato(minutes, notify_msg): 54 | start_time = time.perf_counter() 55 | while True: 56 | diff_seconds = int(round(time.perf_counter() - start_time)) 57 | left_seconds = minutes * 60 - diff_seconds 58 | if left_seconds <= 0: 59 | print('') 60 | break 61 | 62 | seconds_slot = int(left_seconds % 60) 63 | seconds_str = str(seconds_slot) if seconds_slot >= 10 else '0{}'.format(seconds_slot) 64 | 65 | countdown = '{}:{} ⏰'.format(int(left_seconds / 60), seconds_str) 66 | duration = min(minutes, 25) 67 | progressbar(diff_seconds, minutes * 60, duration, countdown) 68 | time.sleep(1) 69 | 70 | notify_me(notify_msg) 71 | 72 | 73 | def progressbar(curr, total, duration=10, extra=''): 74 | frac = curr / total 75 | filled = round(frac * duration) 76 | print('\r', '🍅' * filled + '--' * (duration - filled), '[{:.0%}]'.format(frac), extra, end='') 77 | 78 | 79 | def notify_me(msg): 80 | ''' 81 | # macos desktop notification 82 | terminal-notifier -> https://github.com/julienXX/terminal-notifier#download 83 | terminal-notifier -message 84 | 85 | # ubuntu desktop notification 86 | notify-send 87 | 88 | # voice notification 89 | say -v 90 | lang options: 91 | - Daniel: British English 92 | - Ting-Ting: Mandarin 93 | - Sin-ji: Cantonese 94 | ''' 95 | 96 | print(msg) 97 | try: 98 | if sys.platform == 'darwin': 99 | # macos desktop notification 100 | subprocess.run(['terminal-notifier', '-title', '🍅', '-message', msg]) 101 | subprocess.run(['say', '-v', 'Daniel', msg]) 102 | elif sys.platform.startswith('linux'): 103 | # ubuntu desktop notification 104 | subprocess.Popen(["notify-send", '🍅', msg]) 105 | else: 106 | # windows? 107 | # TODO: windows notification 108 | pass 109 | 110 | except: 111 | # skip the notification error 112 | pass 113 | 114 | 115 | def help(): 116 | appname = sys.argv[0] 117 | appname = appname if appname.endswith('.py') else 'tomato' # tomato is pypi package 118 | print('====== 🍅 Tomato Clock =======') 119 | print(f'{appname} # start a {WORK_MINUTES} minutes tomato clock + {BREAK_MINUTES} minutes break') 120 | print(f'{appname} -t # start a {WORK_MINUTES} minutes tomato clock') 121 | print(f'{appname} -t # start a minutes tomato clock') 122 | print(f'{appname} -b # take a {BREAK_MINUTES} minutes break') 123 | print(f'{appname} -b # take a minutes break') 124 | print(f'{appname} -h # help') 125 | 126 | 127 | if __name__ == "__main__": 128 | main() 129 | --------------------------------------------------------------------------------