Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
4aa059d9e6
|
|||
|
0ae283604a
|
|||
| 4d789d674d |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,8 +1,6 @@
|
||||
*.swp
|
||||
*.pyc
|
||||
|
||||
__pycache__
|
||||
|
||||
tags
|
||||
|
||||
venv
|
||||
|
||||
18
LICENSE
18
LICENSE
@@ -1,18 +0,0 @@
|
||||
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,38 +1,16 @@
|
||||
# cmdasana
|
||||
A curses CLI for Asana, using the Asana API.
|
||||
|
||||
## Requirments
|
||||
* python 3
|
||||
Requirments:
|
||||
* [python-asana](https://github.com/Asana/python-asana)
|
||||
* [urwid](http://urwid.org)
|
||||
* [python-dateutil](https://github.com/dateutil/dateutil/)
|
||||
* [urwid (included)](http://urwid.org)
|
||||
* python 2
|
||||
|
||||
## 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='...'
|
||||
Usage:
|
||||
```
|
||||
|
||||
### Install dependencies
|
||||
Using `pip`:
|
||||
```
|
||||
pip3 install asana urwid python-dateutil
|
||||
```
|
||||
|
||||
## Usage
|
||||
```
|
||||
./main.py
|
||||
make
|
||||
./cmdasana.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.
|
||||
|
||||
@@ -25,7 +25,6 @@ class AsanaService(object):
|
||||
]
|
||||
|
||||
STORY_FIELDS = [
|
||||
'created_at',
|
||||
'created_by.name',
|
||||
'html_text',
|
||||
'text',
|
||||
@@ -75,7 +74,7 @@ class AsanaService(object):
|
||||
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, params = {
|
||||
'opt_fields': self.STORY_FIELDS
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
from datetime import timezone
|
||||
import dateutil.parser
|
||||
import dateutil
|
||||
from html.parser import HTMLParser
|
||||
import sys
|
||||
|
||||
@@ -27,7 +26,7 @@ class Task(AsanaObject):
|
||||
return super(Task, self).name()
|
||||
|
||||
def assignee(self):
|
||||
if 'assignee' in self.object_dict and self.object_dict['assignee']:
|
||||
if 'assignee' in self.object_dict:
|
||||
return User(self.object_dict['assignee'])
|
||||
else:
|
||||
return None
|
||||
@@ -40,26 +39,19 @@ class Task(AsanaObject):
|
||||
parser = HTMLTextParser()
|
||||
parser.feed(self.object_dict['html_notes'])
|
||||
parser.close()
|
||||
text = parser.get_formatted_text()
|
||||
if (len(text) > 0):
|
||||
return text
|
||||
else:
|
||||
return ""
|
||||
return parser.get_formatted_text()
|
||||
elif 'notes' in self.object_dict:
|
||||
return self.object_dict['notes']
|
||||
else:
|
||||
return ""
|
||||
|
||||
def due_date(self):
|
||||
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')
|
||||
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'])
|
||||
else:
|
||||
return 'no due date'
|
||||
return None
|
||||
|
||||
def parent(self):
|
||||
if 'parent' in self.object_dict and self.object_dict['parent']:
|
||||
@@ -138,21 +130,6 @@ class Tag(object):
|
||||
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
|
||||
@@ -164,7 +141,6 @@ class HTMLTextParser(HTMLParser):
|
||||
def __init__(self):
|
||||
self.text = []
|
||||
self.tag_stack = []
|
||||
self.indent = 0
|
||||
super().__init__()
|
||||
|
||||
def handle_starttag(self, tag, attrs):
|
||||
@@ -176,11 +152,6 @@ class HTMLTextParser(HTMLParser):
|
||||
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)
|
||||
|
||||
@@ -188,19 +159,14 @@ class HTMLTextParser(HTMLParser):
|
||||
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()
|
||||
data = self.text.pop()
|
||||
tag = 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))
|
||||
self.text.append(tag(data))
|
||||
|
||||
def get_formatted_text(self):
|
||||
formatted = [t.text_format() for t in self.text]
|
||||
print(formatted, file=sys.stderr)
|
||||
return formatted
|
||||
|
||||
|
||||
@@ -211,13 +177,6 @@ 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):
|
||||
if 'html_text' in self.object_dict:
|
||||
parser = HTMLTextParser()
|
||||
|
||||
@@ -1,3 +1,10 @@
|
||||
asana==0.8.2
|
||||
python-dateutil==2.8.0
|
||||
urwid==2.0.1
|
||||
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
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
palette = [
|
||||
('atm_section', 'white,bold', 'dark blue'),
|
||||
('author', 'bold,dark blue', ''),
|
||||
('timestamp', 'underline', ''),
|
||||
('custom_fields', 'dark red', ''),
|
||||
('header', 'bold,light green', ''),
|
||||
('project', 'yellow', ''),
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
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_assignee_click, on_due_date_click):
|
||||
on_comment):
|
||||
self.task = task
|
||||
self.on_subtask_click = on_subtask_click,
|
||||
self.on_project_click = on_project_click,
|
||||
@@ -13,15 +12,13 @@ class TaskDetails(object):
|
||||
|
||||
body = [
|
||||
urwid.Text(('task', task.name())),
|
||||
urwid.Divider('⎼'),
|
||||
urwid.Divider('-'),
|
||||
Memberships(task, on_subtask_click, on_project_click).component(),
|
||||
urwid.Divider('⎼'),
|
||||
Assignee(task, on_assignee_click).component(),
|
||||
DueDate(task, on_due_date_click).component(),
|
||||
urwid.Divider('-'),
|
||||
CustomFields(task).component(),
|
||||
urwid.Divider('⎼'),
|
||||
urwid.Divider('='),
|
||||
urwid.Text(task.description()),
|
||||
urwid.Divider('⎼'),
|
||||
urwid.Divider('-'),
|
||||
]
|
||||
|
||||
if task.subtasks():
|
||||
@@ -41,45 +38,6 @@ 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
|
||||
@@ -117,11 +75,7 @@ class CustomFields(object):
|
||||
class Stories(object):
|
||||
def __init__(self, stories):
|
||||
components = [
|
||||
urwid.Text([
|
||||
('timestamp', s.created_at().strftime('%Y-%m-%d %H:%M')),
|
||||
' ',
|
||||
('author', s.creator()),
|
||||
] + s.text())
|
||||
urwid.Text([('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', 'Later'))
|
||||
urwid.Text(('atm_section', 'Upcoming'))
|
||||
] + [TaskRow(t, self.callback) for t in self.later]
|
||||
)
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user