Skip to content

Commit

Permalink
feat: 🎉 Allow scheduling basic polls and saving them to AW
Browse files Browse the repository at this point in the history
  • Loading branch information
bcbernardo committed Aug 8, 2021
0 parents commit 3cd6b98
Show file tree
Hide file tree
Showing 16 changed files with 1,620 additions and 0 deletions.
148 changes: 148 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@

# Created by https://www.toptal.com/developers/gitignore/api/python
# Edit at https://www.toptal.com/developers/gitignore?templates=python

### Python ###
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# End of https://www.toptal.com/developers/gitignore/api/python

# VSCode
.vscode
21 changes: 21 additions & 0 deletions LICENSES/MIT.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) <year> <copyright holders>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
154 changes: 154 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
<!--
SPDX-FileCopyrightText: 2021 Bernardo Chrispim Baron <[email protected]>
SPDX-License-Identifier: MIT
-->

# aw-watcher-ask

An [ActivityWatch][] watcher to pose questions to the user and record her
answers.

This watcher uses [Zenity][Zenity Manual] to present dialog boxes to the user, and stores her answers in a locally running instance of ActivityWatch. This can be useful to poll all sorts of information on a periodical or random basis. The inspiration comes from the [experience sampling method (ESM)](https://en.wikipedia.org/wiki/Experience_sampling_method) used in psychological studies, as well as from the [quantified self](https://en.wikipedia.org/wiki/Quantified_self) movement.

[ActivityWatch]: https://activitywatch.readthedocs.io/en/latest/

## Table of Contents

- [aw-watcher-ask](#aw-watcher-ask)
- [Table of Contents](#table-of-contents)
- [Install](#install)
- [Using `pip`/`pipx`](#using-pippipx)
- [From source](#from-source)
- [Usage](#usage)
- [CLI](#cli)
- [Accessing the data](#accessing-the-data)
- [Security](#security)
- [Limitations and Roadmap](#limitations-and-roadmap)
- [Maintainers](#maintainers)
- [Contributing](#contributing)
- [License](#license)

## Install

### Using `pip`/`pipx`

Create a [virtual environment][venv], activate it and run:

```sh
$ python3 -m pip install git+https://github.com/bcbernardo/aw-watcher-ask.git
Collecting git+https://github.com/bcbernardo/aw-watcher-ask.git
... ...
Installing collected packages: aw-watcher-ask
Successfully installed aw-watcher-ask-0.1.0
```

Alternatively, you may use [`pipx`][pipx] to abstract away the creation of the virtual environment, and make sure the package is globally available:

```sh
$ pipx install git+https://github.com/bcbernardo/aw-watcher-ask.git
installed package aw-watcher-ask 0.1.0, Python 3.9.6
These apps are now globally available
- aw-watcher-ask
done! ✨ 🌟 ✨
```

[venv]: https://docs.python.org/3/tutorial/venv.html
[pipx]: https://pypa.github.io/pipx/

### From source

To install the watcher, clone the repository to your local filesystem and
install it with [poetry](https://python-poetry.org/docs):

```sh
$ git clone https://github.com/bcbernardo/aw-watcher-ask.git
$ cd aw-watcher-ask
$ poetry install
... ...
Installing the current project: aw-watcher-ask (0.1.0)
$ poetry shell # alternatively, add `poetry run` before every command in the examples below
```

## Usage

Before you start using `aw-watcher-input`, make sure you have ActivityWatch [installed and running][AW installation].

[AW installation]: https://docs.activitywatch.net/en/latest/getting-started.html

### CLI

The following command will show the dialog box below each hour at 00 minutes
and 00 seconds, wait up to 120 seconds for the user's response, and save it to
a bucket in the local ActivityWatcher instance.

```sh
$ aw-watcher-ask run --question-id "happiness.level" --question-type="question" --title="My happiness level" --text="Are you feeling happy right now?" --timeout=120 --schedule "0 */1 * * * 0"
... ...
```

![Example dialog asking if the user is happy](./assets/img/example_dialog.png)

Check `aw-watcher-ask run --help` to see all required and optional control parameters.

The `--question-id` is used to identify this particular question in the ActivityWatcher a `aw-watcher-input` bucket, and is therefore mandatory.

The `question-type` parameters is also required and should be one of Zenity's supported [dialog types][Zenity Manual] (complex types such as `forms`, `file-selection` and `list` have not been implemented yet). All options supported by these dialog types are accepted by `aw-watcher-ask run` as extra parameters, and passed unaltered to Zenity under the hood.

[Zenity Manual]: https://help.gnome.org/users/zenity/stable/

### Accessing the data

All data gathered is stored under `aw-watcher-ask_localhost.localdomain` bucket (or `test-aw-watcher-ask_localhost.localdomain`, when running with the `--testing` flag) in the local ActivityWatch endpoint. Check ActivityWatch [REST API documentation][AW API] to learn how to get the stored events programatically, so that you can apply some custom analysis.

[AW API]: https://docs.activitywatch.net/en/latest/api/rest.html

## Security

As other ActivityWatcher [watchers][AW watchers], `aw-watcher-ask` communicates solely with the locally running AW server instance. All data collected is stored in your machine.

[AW watchers]: https://docs.activitywatch.net/en/latest/watchers.html

## Limitations and Roadmap

`aw-watcher-ask` is in a very early development stage. Expect bugs and strange behaviors when using it.

This package uses `zenity` utility, which must be installed in the system and globally accessible through the command line. Zenity comes pre-installed with most Linux installations, and can be installed from all major package repositories (`apt`, `dnf`, `pacman`, `brew` etc.).

Porting Zenity to Windows is not trivial. If you use Windows, you may give @ncruces' [Go port](https://github.com/ncruces/zenity) a shot, as it is supposed to be cross-platform. It have not been tested with `aw-watcher-ask` though, and may therefore behave unexpectedly.

`aw-watcher-ask` does not currently have a way of storing the questions made, and scheduling them every time the system restarts. We want to implement this eventually, but for now you should wrap all questions you want to schedule in a (shell) script and configure your system to execute it at every startup.

## Maintainers

- Bernardo Chrispim Baron ([@bcbernardo](https://github.com/bcbernardo))

## Contributing

PRs accepted. Please [open an issue][new issue] if you have an idea for enhancement or have spotted a bug.

[new issue]: https://github.com/bcbernardo/aw-watcher-ask/issues/new/choose

## License

MIT License

Copyright (c) 2021 Bernardo Chrispim Baron

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Binary file added assets/img/example_dialog.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 3cd6b98

Please sign in to comment.