diff options
author | Cody Hiar <codyfh@gmail.com> | 2018-03-23 21:00:18 -0600 |
---|---|---|
committer | Cody Hiar <codyfh@gmail.com> | 2018-03-23 21:00:18 -0600 |
commit | 1674709eaf04923b8dac4a13ef7661803a4e1c4d (patch) | |
tree | b5c8cd8745342e0e00b5df5bb1a18e213d0683e2 | |
parent | e3fb796429c674f2b15a3320144ecd3fbf3139f0 (diff) |
Adding ability to add time record to task
-rw-r--r-- | README.md | 2 | ||||
-rwxr-xr-x | cli.py | 24 | ||||
-rw-r--r-- | pyactivecollab.py | 4 | ||||
-rw-r--r-- | requirements.txt | 1 |
4 files changed, 23 insertions, 8 deletions
@@ -3,7 +3,7 @@ Python 3 only Cli app for working with the self hosted collab api. Very unstable and prone to breaking. -https://developers.activecollab.com/api-documentation/v1/people/users/all.html +https://developers.activecollab.com/api-documentation # Getting Started @@ -25,32 +25,42 @@ def create_time_record(ac): completer = FuzzyCompleter(suggestions) text = prompt('(Project)> ', completer=completer) project = next(x for x in projects if x['name'] == text) - # Value + # Get Task + tasks = ac.get_tasks_by_project(project['id'])['tasks'] + suggestions = [x['name'] for x in tasks] + completer = FuzzyCompleter(suggestions) + text = prompt('(Task)> ', completer=completer) + if text: + task = next(x for x in tasks if x['name'] == text) + else: + task = None + # Get Value value = prompt('(Value)> ') # If integer is passed then treat it as minutes if ('.' not in value) and (':' not in value): value = float(value) / 60 - # Job Type + # Get Job Type job_types = ac.get_job_types() suggestions = [x['name'] for x in job_types] completer = FuzzyCompleter(suggestions) text = prompt('(Job Type)> ', completer=completer) job_type = next(x for x in job_types if x['name'] == text) - # Date + # Get Date completer = DateFuzzyCompleter() text = prompt('(Date)> ', completer=completer) choosen_date = datetime.datetime.strptime(text, '%a, %Y-%m-%d') - # Billable + # Get Billable billable_choices = {True: 1, False: 0} billable = confirm('(Billable (y/n))> ') billable = billable_choices[billable] - # Summary + # Get Summary summary = prompt('(Summary)> ', enable_open_in_editor=True) - # User + # Get User users = ac.get_users() user = next(x for x in users if x['email'] == ac.config.user) data = { 'value': value, + 'task_id': task['id'] if task else None, 'user_id': user['id'], 'job_type_id': job_type['id'], 'record_date': choosen_date.strftime('%Y-%m-%d'), @@ -181,5 +191,5 @@ def main(): if __name__ == '__main__': try: main() - except KeyboardInterrupt: + except (KeyboardInterrupt, EOFError): print('Have a nice day!') diff --git a/pyactivecollab.py b/pyactivecollab.py index d8ae306..e37d37a 100644 --- a/pyactivecollab.py +++ b/pyactivecollab.py @@ -95,3 +95,7 @@ class ActiveCollab(object): def get_time_records(self, user_id: str) -> Dict: """Get the time records for a user.""" return self.get('/users/{}/time-records'.format(user_id)) + + def get_tasks_by_project(self, project_id: str) -> Dict: + """Get the tasks for a specific project.""" + return self.get('/projects/{}/tasks'.format(project_id)) diff --git a/requirements.txt b/requirements.txt index be697e7..12ec3db 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,3 +2,4 @@ requests==2.18.4 fuzzyfinder==2.1.0 prompt-toolkit==1.0.15 blessings==1.6.1 +ipython==6.0.0 |