From 1674709eaf04923b8dac4a13ef7661803a4e1c4d Mon Sep 17 00:00:00 2001 From: Cody Hiar Date: Fri, 23 Mar 2018 21:00:18 -0600 Subject: Adding ability to add time record to task --- README.md | 2 +- cli.py | 24 +++++++++++++++++------- pyactivecollab.py | 4 ++++ requirements.txt | 1 + 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 3cfd311..c490933 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/cli.py b/cli.py index b794dde..389edb8 100755 --- a/cli.py +++ b/cli.py @@ -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 -- cgit v1.2.3