Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 49 additions & 4 deletions 23/clamytoe/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# pyTrack
> Simple project/task time tracker for Python 3.6.0+.

> Simple project/task time tracker for Python 3.

[![GitHub issues][issues-image]][issues-url]
[![GitHub forks][fork-image]][fork-url]
Expand All @@ -20,8 +21,35 @@ cd Projects
git clone https://github.com/clamytoe/pyTrack.git
python3.6 -m venv venv
source ./venv/bin/activate
pip install -r requirements.txt
python setup.py install
pip install .
```

These are all of the packages that get installed:

```bash
pip freeze
click==6.7
dateparser==0.6.0
humanize==0.5.1
maya==0.3.2
peewee==2.10.1
pendulum==1.2.4
python-dateutil==2.6.0
pyTrack==0.1.2
pytz==2017.2
pytzdata==2017.2
regex==2017.6.23
ruamel.yaml==0.15.15
six==1.10.0
tzlocal==1.4
```

## Uninstall

Uninstalling the package is very simple.

```bash
pip uninstall pyTrack
```

## Usage example
Expand All @@ -45,6 +73,7 @@ Commands:
```

### List all projects

To list all of the projects that you are currently tracking:

```bash
Expand All @@ -58,6 +87,7 @@ pytrack
The project marked with an ``*`` is the currently selected project. This means that the **start** and **stop** commands will apply to that project.

### Add a new project

To add a new project use the **add** command followed by the name of your project. If longer than one word, enclose it in quotes.

```bash
Expand All @@ -69,6 +99,7 @@ Selected: [3] Replace the motor on the A/C unit
The project is added and selected as the default project.

### Remove a project

To remove a project use the **remove** command followed by the project id.

> NOTE: To get the project id, just run **pytrack** by itself.
Expand All @@ -83,6 +114,7 @@ Removed [3] Replace the motor on the A/C unit
You are asked to confirm your action and a confirmation message is displayed.

### Select a project

To switch the default project, use the **select** command.

```bash
Expand All @@ -91,6 +123,7 @@ Selected: [1] Put together a README.md file
```

### Start tracking the currently selected project

If you are ready to work on a project that you want to track, simply issue the **start** command to start tracking it.

```bash
Expand All @@ -107,6 +140,7 @@ pytrack
```

### Stop tracking the currently ACTIVE project

When you are finished or are read to take a break simply run the **stop** command.

```bash
Expand All @@ -127,6 +161,7 @@ The default project will remain selected until you add a new project or you chan
> NOTE: Feel free to take as many breaks as needed, you can always start tracking once again at any time.

### Reset the database

If you have completed all of your projects and you want to start with a clean slate so that your new projects don't start at the last created project id, simply **reset** the database.

```bash
Expand All @@ -139,18 +174,28 @@ All records have been removed.
> WARNING: This is unrecoverable! Make sure that you truly want to delete all logs!

## TODO

* I plan on adding an option to output the logs into a csv file.

## Development setup

If you would like to install this in order to play around with the code and make modifications yourself, simply change the last command in the installation instructions above to the following:

```bash
python setup.py develop
pip install -e .
```

## Release History

* 0.1.2
* CHANGE: Modified to use pip to install the package.
* 0.1.1
* CHANGE: Modified imports to utilize namespaces properly.
* 0.1.0
* CHANGE: Moved the database file into the home directory of the user because when installed, the database was getting created from wherever the command was being issued.
* CHANGE: Renamed the database file.
* 0.0.6
* CHANGE: Removed all f-strings so that the code could be used in older versions of Python.
* 0.0.5
* FIX: Fixed bug when the currently selected project is removed, no other is selected as the default.
* 0.0.4
Expand Down
8 changes: 4 additions & 4 deletions 23/clamytoe/main.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/usr/bin/env python3.6
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from sys import argv

import click
from peewee import OperationalError

from pytrack.models import db, Log, Project
from pytrack.pytrack import get_projects, add_project, select_project, remove_project
from pytrack.pytrack import start_tracking, stop_tracking, reset_db
from pytrack import db, Log, Project
from pytrack import get_projects, add_project, select_project, remove_project
from pytrack import start_tracking, stop_tracking, reset_db


def main():
Expand Down
2 changes: 1 addition & 1 deletion 23/clamytoe/pytrack/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# -*- coding: utf-8 -*-
from .models import db, Log, Project
from .pytrack import get_projects, add_project, select_project, remove_project
from .pytrack import start_tracking, stop_tracking, reset_db
from .pytrack import start_tracking, stop_tracking, reset_db
13 changes: 11 additions & 2 deletions 23/clamytoe/pytrack/models.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
# -*- coding: utf-8 -*-
from os import mkdir, path

from peewee import BooleanField, CharField, DateTimeField, ForeignKeyField, PrimaryKeyField
from peewee import Model, OperationalError, SqliteDatabase

DATABASE = 'pyTrack_db.sqlite'
DB_NAME = 'pyTrack.db'
HOME = path.expanduser('~')
DB_FOLDER = path.join(HOME, '.pytrack')
DATABASE = path.join(DB_FOLDER, DB_NAME)

if not path.exists(DB_FOLDER):
mkdir(DB_FOLDER)

db = SqliteDatabase(DATABASE)


Expand All @@ -21,7 +30,6 @@ class Project(BaseModel):
status = BooleanField(default=0)
duration = CharField(default='0:00:00')


class Meta:
db_table = 'projects'

Expand All @@ -38,6 +46,7 @@ class Log(BaseModel):
class Meta:
db_table = 'logs'


if __name__ == '__main__':
try:
Project.create_table()
Expand Down
36 changes: 18 additions & 18 deletions 23/clamytoe/pytrack/pytrack.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python3.6
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from maya import get_localzone, MayaInterval, now, parse

Expand All @@ -15,9 +15,9 @@ def get_projects(display=False):
projects.append(project)
if display:
if project.selected:
print(f'*[{project.id}] {project.duration} {STATE[project.status]}: {project.name}')
print('*[{}] {} {}: {}'.format(project.id, project.duration, STATE[project.status], project.name))
else:
print(f' [{project.id}] {project.duration} {STATE[project.status]}: {project.name}')
print(' [{}] {} {}: {}'.format(project.id, project.duration, STATE[project.status], project.name))
else:
print('You are not currently tracking any projects.')
return projects
Expand All @@ -32,9 +32,9 @@ def get_selected(display=True):
selected = project
if display:
if selected:
print(f'Selected: {selected.name}')
print('Selected: {}'.format(selected.name))
else:
print(f'Selected: {selected}')
print('Selected: {}'.format(selected))

return selected

Expand Down Expand Up @@ -74,7 +74,7 @@ def update_project(project):
project.duration = duration
project.status = 0
project.save()
print(f'Deactivating: {project.name} with total time of {project.duration}')
print('Deactivating: {} with total time of {}'.format(project.name, project.duration))


def add_project(name):
Expand All @@ -83,12 +83,12 @@ def add_project(name):
active = get_active()

if active:
print(f'There is an active project: [{active.id}] {active.name}')
print('There is an active project: [{}] {}'.format(active.id, active.name))
print('Please close that out before adding another project.')
else:
project = Project.create(name=name)
project.save()
print(f'Added Project: [{project.id}] {project.name}')
print('Added Project: [{}] {}'.format(project.id, project.name))
select_project(project.id)


Expand All @@ -98,8 +98,8 @@ def select_project(id):
active = get_active()

if active:
print(f'Cannot make project selection while there is an active project!')
print(f'Currently tracking: {active.name}')
print('Cannot make project selection while there is an active project!')
print('Currently tracking: {}'.format(active.name))
else:
projects = get_projects()

Expand All @@ -114,13 +114,13 @@ def select_project(id):
if project.id == id:
project.selected = True
project.save()
print(f'Selected: [{project.id}] {project.name}')
print('Selected: [{}] {}'.format(project.id, project.name))
else:
# unselect all others
project.selected = False
project.save()
else:
print(f'[{id}] is not a valid entry. \nChoose from the following:\n')
print('[{}] is not a valid entry. \nChoose from the following:\n'.format(id))
_ = get_projects(display=True)


Expand All @@ -139,17 +139,17 @@ def remove_project(id):
select = proj.id

if project:
print(f'About to remove [{project.id}] {project.name}')
print('About to remove [{}] {}'.format(project.id, project.name))
answer = input('Are you sure (y/n): ')
if 'y' in answer.lower():
project.delete_instance()
print(f'Removed [{project.id}] {project.name}')
print('Removed [{}] {}'.format(project.id, project.name))
if selected and select:
select_project(select)
else:
print('Aborted')
else:
print(f'Project [{id}] does not exists!')
print('Project [{}] does not exists!'.format(id))


def reset_db():
Expand All @@ -172,14 +172,14 @@ def start_tracking():
active = get_active()

if active:
print(f'Already tracking {active.name}!')
print('Already tracking {}!'.format(active.name))
else:
project = get_selected(display=False)
log = Log.create(project=project, start_time=now().datetime())
log.save()
project.status = 1
project.save()
print(f'Activating: {project.name}')
print('Activating: {}'.format(project.name))


def stop_tracking():
Expand All @@ -198,4 +198,4 @@ def stop_tracking():
# update the project's status and duration time
update_project(active)
else:
print(f'There are currently no active projects...')
print('There are currently no active projects...')
9 changes: 5 additions & 4 deletions 23/clamytoe/setup.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
#!/usr/bin/env python3.6
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from setuptools import setup


setup(
name='pyTrack',
version='0.0.5',
version='0.1.2',
author='Martin Uribe',
author_email='clamytoe@gmail.com',
url='https://github.com/clamytoe/pyTrack',
description='Simple project/task time tracker for Python 3.6.0+',
description='Simple project/task time tracker for Python 3',
long_description='Helps you keep track of how much time you spend on your projects and tasks. A sqlite database '
'is used to track your time logs, and it is kept simply by only implementing as few commands as '
'needed to get a full featured application. You can add/remove multiple projects, start/stop '
'tracking any of them, or completely reset the database to start with a clean slate',
license='MIT',
keywords='3.6 project tracker peewee click maya',
packages=['pytrack'],
keywords='project tracker peewee click maya',
py_modules=[
'main',
'pytrack.models',
Expand Down