From bc925ef767339b52da606f6457346747bd86a875 Mon Sep 17 00:00:00 2001 From: Tobias Schmidl Date: Mon, 21 Sep 2020 08:17:04 +0200 Subject: [PATCH] added initial --- .gitignore | 158 +++++++++++++++++++++++++++++++++++++++++++++++ .style.yapf | 33 ++++++++++ pylama.ini | 14 +++++ requirements.txt | 4 ++ timewarrior.py | 48 ++++++++++++++ 5 files changed, 257 insertions(+) create mode 100644 .gitignore create mode 100644 .style.yapf create mode 100644 pylama.ini create mode 100644 requirements.txt create mode 100755 timewarrior.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8c71a74 --- /dev/null +++ b/.gitignore @@ -0,0 +1,158 @@ + +### 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/ +pip-wheel-metadata/ +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 +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/ + +### Vim +# Swap +[._]*.s[a-v][a-z] +!*.svg # comment out if you don't need vector files +[._]*.sw[a-p] +[._]s[a-rt-v][a-z] +[._]ss[a-gi-z] +[._]sw[a-p] + +# Session +Session.vim +Sessionx.vim + +# Temporary +.netrwhist +*~ +# Auto-generated tag files +tags +# Persistent undo +[._]*.un~ diff --git a/.style.yapf b/.style.yapf new file mode 100644 index 0000000..b34c3f4 --- /dev/null +++ b/.style.yapf @@ -0,0 +1,33 @@ +[style] + +# Insert a blank line before a module docstring. +blank_line_before_module_docstring=True + +# The column limit. +column_limit=120 + +# Split before the '.' if we need to split a longer expression: +# +# foo = ('This is a really long string: {}, {}, {}, {}'.format(a, b, c, d)) +# +# would reformat to something like: +# +# foo = ('This is a really long string: {}, {}, {}, {}' +# .format(a, b, c, d)) +split_before_dot=True + +# Set to True to split list comprehensions and generators that have +# non-trivial expressions and multiple clauses before each of these +# clauses. For example: +# +# result = [ +# a_long_var + 100 for a_long_var in xrange(1000) +# if a_long_var % 10] +# +# would reformat to something like: +# +# result = [ +# a_long_var + 100 +# for a_long_var in xrange(1000) +# if a_long_var % 10] +split_complex_comprehension=True diff --git a/pylama.ini b/pylama.ini new file mode 100644 index 0000000..48d15c9 --- /dev/null +++ b/pylama.ini @@ -0,0 +1,14 @@ +[pylama] +format = pylint +linters = mccabe,pep257,pydocstyle,pep8,pycodestyle,pyflakes,pylint,isort +ignore = D203 +skip=.env/* + +[pylama:pycodestyle] +max_line_length = 120 + +[pylama:pep8] +max_line_length = 120 + +[pylama:pylint] +max_line_length = 120 diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..bbbc09e --- /dev/null +++ b/requirements.txt @@ -0,0 +1,4 @@ +pylama>=7.7.0 +pylint>=2.3.0 +yapf>=0.27.0 +timew>=0.0.22 diff --git a/timewarrior.py b/timewarrior.py new file mode 100755 index 0000000..a029d06 --- /dev/null +++ b/timewarrior.py @@ -0,0 +1,48 @@ +#! /usr/bin/env python3 +# -*- coding: utf-8 -*- + +"""Timewarrior adapter for `argos `.""" +# timewarrior +# v1.0 +# Tobias Schmidl +# schtobia +# Greps and formats data from timewarrior. +# +# python,timew +# https://github.com/schtobia/argos-timewarrior/blob/master/timewarrior.py + + +import functools +import locale +from datetime import datetime, timedelta + +from timew import TimeWarrior + +TW = TimeWarrior() +TIMEFORMATTER = '%Y%m%dT%H%M%S%z' +locale.setlocale(locale.LC_ALL, '') +RESULTS = sorted(map( + lambda x: { + 'start': + datetime.strptime(x['start'], TIMEFORMATTER).astimezone(tz=None), + 'end': + datetime.strptime(x['end'], TIMEFORMATTER).astimezone(tz=None) + if 'end' in x else datetime.now().astimezone(tz=None), + 'id': + x['id'], + 'tags': + x['tags'] + }, TW.summary()), + key=lambda x: x['start']) + +print("TW: {}\n-----".format( + str(functools.reduce(lambda total, x: total + x['end'] - x['start'], RESULTS, timedelta())).split(sep='.', maxsplit=1)[0] +)) +print( + " | font=monospace | size=8\n".join( + map( + lambda x: str({ + 'start': datetime.strftime(x['start'], "%x %X"), + 'end': datetime.strftime(x['end'], "%x %X"), + 'tags': x['tags'] + }), RESULTS)), "| font=monospace | size=8")