Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 04a6361d6b | |||
|
1ed1ca1065
|
|||
|
2a9b674cc5
|
|||
|
8a86d4b559
|
|||
|
da9dd3578f
|
|||
| 364a69fb3b | |||
| 47eff82d3f | |||
|
52ee057924
|
|||
|
1d81648ee4
|
|||
|
1337dc9f80
|
|||
| 5571afe977 | |||
| c97f79a081 | |||
| 1b174219d5 | |||
|
3e65d08bbf
|
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,6 +1,8 @@
|
||||
*.swp
|
||||
*.pyc
|
||||
|
||||
__pycache__
|
||||
|
||||
tags
|
||||
|
||||
venv
|
||||
|
||||
18
LICENSE
Normal file
18
LICENSE
Normal file
@@ -0,0 +1,18 @@
|
||||
Copyright 2018 Aaron Gutierrez
|
||||
|
||||
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.
|
||||
34
README.md
34
README.md
@@ -1,16 +1,38 @@
|
||||
# cmdasana
|
||||
A curses CLI for Asana, using the Asana API.
|
||||
|
||||
Requirments:
|
||||
## Requirments
|
||||
* python 3
|
||||
* [python-asana](https://github.com/Asana/python-asana)
|
||||
* [urwid (included)](http://urwid.org)
|
||||
* python 2
|
||||
* [urwid](http://urwid.org)
|
||||
* [python-dateutil](https://github.com/dateutil/dateutil/)
|
||||
|
||||
Usage:
|
||||
## Setup
|
||||
### Create an Asana OAuth app
|
||||
See [instructions from Asana](https://asana.com/developers/documentation/getting-started/auth#register-an-app)
|
||||
on how to create a new app. Use `urn:ietf:wg:oauth:2.0:oob` as the redirect
|
||||
URL.
|
||||
|
||||
Once you create your app, save your client ID and secret in a file `secrets.py`:
|
||||
```python
|
||||
CLIENT_ID='...'
|
||||
CLIENT_SECRET='...'
|
||||
```
|
||||
make
|
||||
./cmdasana.py
|
||||
|
||||
### Install dependencies
|
||||
Using `pip`:
|
||||
```
|
||||
pip3 install asana urwid python-dateutil
|
||||
```
|
||||
|
||||
## Usage
|
||||
```
|
||||
./main.py
|
||||
```
|
||||
|
||||
When you first cmdasana, you will need to authorize the app in your browser.
|
||||
Copy and paste your OAuth key into the terminal to get started.
|
||||
|
||||
## Navigation
|
||||
Use arrow keys to navigate, `<enter>` to "click", and `<backspace>` to return to
|
||||
the previous page.
|
||||
|
||||
@@ -3,6 +3,7 @@ from models.models import *
|
||||
class AsanaService(object):
|
||||
TASK_FIELDS = [
|
||||
'name',
|
||||
'html_notes',
|
||||
'notes',
|
||||
'assignee.name',
|
||||
'assignee_status',
|
||||
@@ -23,6 +24,14 @@ class AsanaService(object):
|
||||
'subtasks.name',
|
||||
]
|
||||
|
||||
STORY_FIELDS = [
|
||||
'created_at',
|
||||
'created_by.name',
|
||||
'html_text',
|
||||
'text',
|
||||
'type'
|
||||
]
|
||||
|
||||
def __init__(self, client):
|
||||
self.client = client
|
||||
self.completed_tasks = False
|
||||
@@ -32,17 +41,6 @@ class AsanaService(object):
|
||||
def __wrap__(self, Klass, values):
|
||||
return map(Klass, values)
|
||||
|
||||
def get_tasks(self, project_id):
|
||||
params = {
|
||||
'completed_since': '' if self.completed_tasks else 'now',
|
||||
'opt_fields': self.TASK_FIELDS,
|
||||
}
|
||||
|
||||
return self.__wrap__(
|
||||
Task,
|
||||
self.client.tasks.find_by_project(project_id, params=params)
|
||||
)
|
||||
|
||||
def get_my_tasks(self):
|
||||
return self.__wrap__(
|
||||
Task,
|
||||
@@ -54,6 +52,11 @@ class AsanaService(object):
|
||||
})
|
||||
)
|
||||
|
||||
def get_project(self, project_id):
|
||||
return Project(
|
||||
self.client.projects.find_by_id(project_id)
|
||||
)
|
||||
|
||||
def get_task(self, task_id):
|
||||
return Task(self.client.tasks.find_by_id(
|
||||
task_id,
|
||||
@@ -61,8 +64,21 @@ class AsanaService(object):
|
||||
'opt_fields': self.TASK_FIELDS
|
||||
}
|
||||
))
|
||||
|
||||
|
||||
def get_tasks(self, project_id):
|
||||
params = {
|
||||
'completed_since': '' if self.completed_tasks else 'now',
|
||||
'opt_fields': self.TASK_FIELDS,
|
||||
}
|
||||
|
||||
return self.__wrap__(
|
||||
Task,
|
||||
self.client.tasks.find_by_project(project_id, params=params)
|
||||
)
|
||||
|
||||
def get_stories(self, task_id):
|
||||
stories = self.client.stories.find_by_task(task_id)
|
||||
stories = self.client.stories.find_by_task(task_id, params = {
|
||||
'opt_fields': self.STORY_FIELDS
|
||||
})
|
||||
filtered_stories = filter(lambda s: s['type'] == 'comment', stories)
|
||||
return self.__wrap__(Story, filtered_stories)
|
||||
|
||||
148
models/models.py
148
models/models.py
@@ -1,4 +1,6 @@
|
||||
import dateutil
|
||||
from datetime import timezone
|
||||
import dateutil.parser
|
||||
from html.parser import HTMLParser
|
||||
import sys
|
||||
|
||||
class AsanaObject(object):
|
||||
@@ -25,7 +27,7 @@ class Task(AsanaObject):
|
||||
return super(Task, self).name()
|
||||
|
||||
def assignee(self):
|
||||
if 'assignee' in self.object_dict:
|
||||
if 'assignee' in self.object_dict and self.object_dict['assignee']:
|
||||
return User(self.object_dict['assignee'])
|
||||
else:
|
||||
return None
|
||||
@@ -34,18 +36,30 @@ class Task(AsanaObject):
|
||||
return self.object_dict['assignee_status']
|
||||
|
||||
def description(self):
|
||||
if 'notes' in self.object_dict:
|
||||
if 'html_notes' in self.object_dict:
|
||||
parser = HTMLTextParser()
|
||||
parser.feed(self.object_dict['html_notes'])
|
||||
parser.close()
|
||||
text = parser.get_formatted_text()
|
||||
if (len(text) > 0):
|
||||
return text
|
||||
else:
|
||||
return ""
|
||||
elif 'notes' in self.object_dict:
|
||||
return self.object_dict['notes']
|
||||
else:
|
||||
return None
|
||||
return ""
|
||||
|
||||
def due_date(self):
|
||||
if 'due_at' in self.object_dict:
|
||||
return dateutil.parser.parse(self.object_dict['due_at'])
|
||||
elif 'due_one' in self.object_dict:
|
||||
return dateutil.parser.parse(self.object_dict['due_on'])
|
||||
if 'due_at' in self.object_dict and self.object_dict['due_at']:
|
||||
datetime = dateutil.parser.parse(self.object_dict['due_at'])
|
||||
datetime = datetime.replace(tzinfo=timezone.utc).astimezone(tz=None)
|
||||
return datetime.strftime('%b %d, %Y %H:%M')
|
||||
elif 'due_on' in self.object_dict and self.object_dict['due_on']:
|
||||
date = dateutil.parser.parse(self.object_dict['due_on'])
|
||||
return date.strftime('%b %d, %Y')
|
||||
else:
|
||||
return None
|
||||
return 'no due date'
|
||||
|
||||
def parent(self):
|
||||
if 'parent' in self.object_dict and self.object_dict['parent']:
|
||||
@@ -89,6 +103,107 @@ class CustomField(AsanaObject):
|
||||
|
||||
return ''
|
||||
|
||||
class Strong(object):
|
||||
def __init__(self, body):
|
||||
self.body = body
|
||||
|
||||
def text_format(self):
|
||||
return ('strong', self.body.text_format())
|
||||
|
||||
class Italic(object):
|
||||
def __init__(self, body):
|
||||
self.body = body
|
||||
|
||||
def text_format(self):
|
||||
return ('italic', self.body.text_format())
|
||||
|
||||
class Underline(object):
|
||||
def __init__(self, body):
|
||||
self.body = body
|
||||
|
||||
def text_format(self):
|
||||
return ('underline', self.body.text_format())
|
||||
|
||||
class Link(object):
|
||||
def __init__(self, body):
|
||||
self.body = body
|
||||
|
||||
def text_format(self):
|
||||
return ('link', self.body.text_format())
|
||||
|
||||
class Tag(object):
|
||||
def __init__(self, body):
|
||||
self.body = body
|
||||
|
||||
def text_format(self):
|
||||
return self.body.text_format()
|
||||
|
||||
class List(object):
|
||||
def __init__(self, body):
|
||||
self.body = body
|
||||
|
||||
def text_format(self):
|
||||
return self.body.text_format()
|
||||
|
||||
class ListItem(object):
|
||||
def __init__(self, body, indent):
|
||||
self.body = body
|
||||
self.indent = indent
|
||||
|
||||
def text_format(self):
|
||||
return ('', [(' ' * self.indent), '• ', self.body.text_format(), '\n'])
|
||||
|
||||
class Text(object):
|
||||
def __init__(self, body):
|
||||
self.body = body
|
||||
|
||||
def text_format(self):
|
||||
return self.body
|
||||
|
||||
class HTMLTextParser(HTMLParser):
|
||||
def __init__(self):
|
||||
self.text = []
|
||||
self.tag_stack = []
|
||||
self.indent = 0
|
||||
super().__init__()
|
||||
|
||||
def handle_starttag(self, tag, attrs):
|
||||
if tag == 'strong':
|
||||
self.tag_stack.append(Strong)
|
||||
elif tag == 'em':
|
||||
self.tag_stack.append(Italic)
|
||||
elif tag == 'u':
|
||||
self.tag_stack.append(Underline)
|
||||
elif tag == 'a':
|
||||
self.tag_stack.append(Link)
|
||||
elif tag == 'ul' or tag == 'ol':
|
||||
self.indent += 2
|
||||
self.tag_stack.append(List)
|
||||
elif tag == 'li':
|
||||
self.tag_stack.append(ListItem)
|
||||
else:
|
||||
self.tag_stack.append(Tag)
|
||||
|
||||
def handle_data(self, data):
|
||||
self.text.append(Text(data))
|
||||
|
||||
def handle_endtag(self, tag):
|
||||
data = self.text.pop() if len(self.text) > 0 else Text("")
|
||||
Class = self.tag_stack.pop()
|
||||
|
||||
if tag == 'ul' or tag =='ol':
|
||||
self.indent -= 2
|
||||
|
||||
if tag == 'li':
|
||||
self.text.append(Class(data, self.indent))
|
||||
else:
|
||||
self.text.append(Class(data))
|
||||
|
||||
def get_formatted_text(self):
|
||||
formatted = [t.text_format() for t in self.text]
|
||||
return formatted
|
||||
|
||||
|
||||
class Story(AsanaObject):
|
||||
def creator(self):
|
||||
if 'created_by' in self.object_dict:
|
||||
@@ -96,5 +211,18 @@ class Story(AsanaObject):
|
||||
else:
|
||||
return ''
|
||||
|
||||
def created_at(self):
|
||||
if 'created_at' in self.object_dict:
|
||||
return dateutil.parser.parse(self.object_dict['created_at']) \
|
||||
.replace(tzinfo=timezone.utc).astimezone(tz=None)
|
||||
else:
|
||||
return ''
|
||||
|
||||
def text(self):
|
||||
return self.object_dict['text']
|
||||
if 'html_text' in self.object_dict:
|
||||
parser = HTMLTextParser()
|
||||
parser.feed(self.object_dict['html_text'])
|
||||
parser.close()
|
||||
return parser.get_formatted_text()
|
||||
else:
|
||||
return [self.object_dict['text']]
|
||||
|
||||
@@ -1,10 +1,3 @@
|
||||
asana==0.6.5
|
||||
certifi==2017.11.5
|
||||
chardet==3.0.4
|
||||
idna==2.6
|
||||
oauthlib==2.0.6
|
||||
requests==2.14.2
|
||||
requests-oauthlib==0.6.2
|
||||
six==1.10.0
|
||||
urllib3==1.22
|
||||
urwid==1.3.1
|
||||
asana==0.8.2
|
||||
python-dateutil==2.8.0
|
||||
urwid==2.0.1
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
palette = [
|
||||
('atm_section', 'white,bold', 'dark blue'),
|
||||
('author', 'bold,dark blue', ''),
|
||||
('timestamp', 'underline', ''),
|
||||
('custom_fields', 'dark red', ''),
|
||||
('header', 'bold,light green', ''),
|
||||
('project', 'yellow', ''),
|
||||
@@ -8,6 +9,10 @@ palette = [
|
||||
('selected', 'standout', ''),
|
||||
('task', 'light green', ''),
|
||||
('text', '', ''),
|
||||
('strong', 'bold', ''),
|
||||
('underline', 'underline', ''),
|
||||
('link', 'underline,light blue', ''),
|
||||
('italic', 'italics', ''),
|
||||
('workspace', 'white', 'dark blue'),
|
||||
]
|
||||
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import urwid
|
||||
from datetime import date, datetime
|
||||
|
||||
from ui.task_list import TaskRow
|
||||
|
||||
class TaskDetails(object):
|
||||
def __init__(self, task, stories, on_subtask_click, on_project_click,
|
||||
on_comment):
|
||||
on_comment, on_assignee_click, on_due_date_click):
|
||||
self.task = task
|
||||
self.on_subtask_click = on_subtask_click,
|
||||
self.on_project_click = on_project_click,
|
||||
@@ -12,13 +13,15 @@ class TaskDetails(object):
|
||||
|
||||
body = [
|
||||
urwid.Text(('task', task.name())),
|
||||
urwid.Divider('-'),
|
||||
urwid.Divider('⎼'),
|
||||
Memberships(task, on_subtask_click, on_project_click).component(),
|
||||
urwid.Divider('-'),
|
||||
urwid.Divider('⎼'),
|
||||
Assignee(task, on_assignee_click).component(),
|
||||
DueDate(task, on_due_date_click).component(),
|
||||
CustomFields(task).component(),
|
||||
urwid.Divider('='),
|
||||
urwid.Divider('⎼'),
|
||||
urwid.Text(task.description()),
|
||||
urwid.Divider('-'),
|
||||
urwid.Divider('⎼'),
|
||||
]
|
||||
|
||||
if task.subtasks():
|
||||
@@ -38,6 +41,45 @@ class TaskDetails(object):
|
||||
def component(self):
|
||||
return self.details
|
||||
|
||||
class Assignee(object):
|
||||
def __init__(self, task, on_click):
|
||||
if task.assignee():
|
||||
assignee = task.assignee().name()
|
||||
else:
|
||||
assignee = "unassigned"
|
||||
|
||||
|
||||
self.assignee = urwid.SelectableIcon([('strong', 'Assignee: '), ('', assignee)])
|
||||
|
||||
self.on_click = on_click
|
||||
#urwid.connect_signal(self.assignee, 'keypress', self.on_keypress)
|
||||
|
||||
def component(self):
|
||||
return self.assignee
|
||||
|
||||
def on_keypress(self, size, key):
|
||||
if key == "enter":
|
||||
self.on_click()
|
||||
else:
|
||||
return key
|
||||
|
||||
class DueDate(object):
|
||||
def __init__(self, task, on_click):
|
||||
due_date = task.due_date()
|
||||
self.due_date = urwid.SelectableIcon([('strong', 'Due: '), ('', str(task.due_date()))])
|
||||
|
||||
self.on_click = on_click
|
||||
#urwid.connect_signal(self.due_date, 'keypress', self.on_keypress)
|
||||
|
||||
def component(self):
|
||||
return self.due_date
|
||||
|
||||
def on_keypress(self, size, key):
|
||||
if key == "enter":
|
||||
self.on_click()
|
||||
else:
|
||||
return key
|
||||
|
||||
class Memberships(object):
|
||||
def __init__(self, task, on_subtask_click, on_project_click):
|
||||
self.on_project_click = on_project_click
|
||||
@@ -74,11 +116,13 @@ class CustomFields(object):
|
||||
|
||||
class Stories(object):
|
||||
def __init__(self, stories):
|
||||
components = [urwid.Text([
|
||||
('author', s.creator()),
|
||||
s.text(),
|
||||
'\n'
|
||||
]) for s in stories]
|
||||
components = [
|
||||
urwid.Text([
|
||||
('timestamp', s.created_at().strftime('%Y-%m-%d %H:%M')),
|
||||
' ',
|
||||
('author', s.creator()),
|
||||
] + s.text())
|
||||
for s in stories]
|
||||
|
||||
self.stories = urwid.Pile(components)
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ class MyTasks(object):
|
||||
] + [TaskRow(t, self.callback) for t in self.today] + [
|
||||
urwid.Text(('atm_section', 'Upcoming'))
|
||||
] + [TaskRow(t, self.callback) for t in self.upcoming] + [
|
||||
urwid.Text(('atm_section', 'Upcoming'))
|
||||
urwid.Text(('atm_section', 'Later'))
|
||||
] + [TaskRow(t, self.callback) for t in self.later]
|
||||
)
|
||||
),
|
||||
|
||||
5
ui/ui.py
5
ui/ui.py
@@ -32,16 +32,17 @@ class Ui(object):
|
||||
stories,
|
||||
self.task_details,
|
||||
self.task_list,
|
||||
None).component())
|
||||
None, None, None).component())
|
||||
thread = Thread(target=runInThread())
|
||||
thread.start()
|
||||
|
||||
def task_list(self, id):
|
||||
self.nav_stack.append(('project', id))
|
||||
def runInThread():
|
||||
project = self.asana_service.get_project(id)
|
||||
tasks = self.asana_service.get_tasks(id)
|
||||
self.update(TaskList(tasks,
|
||||
'TODO: get project name',
|
||||
project.name(),
|
||||
self.task_details
|
||||
).component())
|
||||
thread = Thread(target=runInThread())
|
||||
|
||||
Reference in New Issue
Block a user