Skip to content

Commit

Permalink
Merge pull request #11 from mschmidtkorth/develop
Browse files Browse the repository at this point in the history
Fix search working without hierarchy levels
Add allow no due date
  • Loading branch information
mschmidtkorth authored Feb 10, 2020
2 parents 4274845 + ef9d5a8 commit 18a1d55
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 36 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ _backup/*
setup.py
automatedTests.py
DO_NOT_COMMIT.md
workflow/.alfredversionchecked
workflow/.alfredversionchecked
*.code-workspace
27 changes: 16 additions & 11 deletions createTask.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def main(wf):
query = wf.args[0]
else:
query = None

taskParameters = json.loads(query)
createTask(taskParameters['inputName'], taskParameters['inputContent'], taskParameters['inputDue'], taskParameters['inputPriority'], taskParameters['inputTags'], taskParameters['inputList'])

Expand All @@ -40,16 +40,20 @@ def createTask(inputName, inputContent, inputDue, inputPriority, inputTags, inpu
'''
if DEBUG > 0:
log.debug('[ Calling API to create task ]')

if not inputList:
inputListId = getConfigValue(confNames['confList'])
else:
# Get value of first key in dictionary {Name, Id} by converting to List. The dict will always contain a single list name+Id the user specified.
inputListId = next(iter(inputList.items()))[1] # Get value for first key of dict

inputDue = datetime.datetime.strptime(str(inputDue)[:len(inputDue) - 10], '%Y-%m-%d %H:%M') # Convert String to datetime. Remove seconds.milliseconds (e.g. :26.614286) from string
inputDueMs = (inputDue - datetime.datetime.fromtimestamp(0)).total_seconds() * 1000.0 # Convert datetime into ms. Use fromtimestamp() to get local timezone instead of utcfromtimestamp()


log.debug(inputDue)
log.debug(inputDue)
log.debug(inputDue)
if inputDue != 'None':
inputDue = datetime.datetime.strptime(str(inputDue)[:len(inputDue) - 10], '%Y-%m-%d %H:%M') # Convert String to datetime. Remove seconds.milliseconds (e.g. :26.614286) from string
inputDueMs = (inputDue - datetime.datetime.fromtimestamp(0)).total_seconds() * 1000.0 # Convert datetime into ms. Use fromtimestamp() to get local timezone instead of utcfromtimestamp()

url = 'https://api.clickup.com/api/v2/list/' + inputListId + '/task'
params = None
headers = {}
Expand All @@ -58,16 +62,17 @@ def createTask(inputName, inputContent, inputDue, inputPriority, inputTags, inpu
data = {}
data['name'] = inputName
data['content'] = inputContent
data['due_date'] = int(inputDueMs)
data['due_date_time'] = True # Translated into true
if inputDue != 'None':
data['due_date'] = int(inputDueMs)
data['due_date_time'] = True # Translated into true
data['priority'] = inputPriority if inputPriority != None else None # Translated into 'null'
data['tags'] = inputTags

if DEBUG > 1:
log.debug(url)
log.debug(headers)
log.debug(data)

try:
import json
request = web.post(url, params = params, data = json.dumps(data), headers = headers)
Expand All @@ -80,7 +85,7 @@ def createTask(inputName, inputContent, inputDue, inputPriority, inputTags, inpu
result = request.json()
if DEBUG > 1:
log.debug('Response: ' + str(result))

# If user pressed 'opt' (optInput == true), we do not want to show a notification, as the task is opened in the browser
hasUserNotPressedOpt = 'optInput' not in os.environ or os.environ['optInput'] == 'false'
if getConfigValue(confNames['confNotification']) == 'true' and (hasUserNotPressedOpt):
Expand Down
13 changes: 7 additions & 6 deletions getTasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@ def getTasks():
url = 'https://api.clickup.com/api/v2/team/' + getConfigValue(confNames['confTeam']) + '/task'
params = {}

if 'space' in getConfigValue(confNames['confHierarchyLimit']):
params['space_ids[]'] = getConfigValue(confNames['confSpace']) # Use [] instead of %5B%5D
if 'folder' in getConfigValue(confNames['confHierarchyLimit']):
params['project_ids[]'] = getConfigValue(confNames['confProject'])
if 'list' in getConfigValue(confNames['confHierarchyLimit']):
params['list_ids[]'] = getConfigValue(confNames['confList'])
if getConfigValue(confNames['confHierarchyLimit']):
if 'space' in getConfigValue(confNames['confHierarchyLimit']):
params['space_ids[]'] = getConfigValue(confNames['confSpace']) # Use [] instead of %5B%5D
if 'folder' in getConfigValue(confNames['confHierarchyLimit']):
params['project_ids[]'] = getConfigValue(confNames['confProject'])
if 'list' in getConfigValue(confNames['confHierarchyLimit']):
params['list_ids[]'] = getConfigValue(confNames['confList'])
params['order_by'] = 'due_date'
# Differentiates between listing all Alfred-created tasks and searching for all tasks (any)
if DEBUG > 0 and len(wf.args) > 1 and wf.args[1] == 'search':
Expand Down
2 changes: 1 addition & 1 deletion info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -1160,7 +1160,7 @@ Uses fuzzy search instead of Alfred filtering.</string>
<key>variablesdontexport</key>
<array/>
<key>version</key>
<string>1.0.2</string>
<string>1.0.3</string>
<key>webaddress</key>
<string>https://github.com/mschmidtkorth/alfred-clickup-msk/</string>
</dict>
Expand Down
67 changes: 50 additions & 17 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
isDoNotDisplayCreate = False
isCustomTagEntered = False


def retrieveLabelsFromAPI():
'''Retrieves list of available Labels from ClickUp.
'''
Expand Down Expand Up @@ -125,10 +126,13 @@ def getPriorities(input):
filteredItems = wf.filter(input, allLabelTitles)
for item in filteredItems:
hasFoundMatch = True
wf3.add_item(title = item.split(' ')[1], valid = False,
wf3.add_item(
title = item.split(' ')[1],
valid = False,
#arg = 'cu ' + query.replace(input, '') + str(priority) + ' ',
autocomplete = query.replace(input, '') + item.split(' ')[0] + ' ',
icon = './prio' + item.split(' ')[0] + '.png')
icon = './prio' + item.split(' ')[0] + '.png'
)
if hasFoundMatch:
wf3.send_feedback()

Expand Down Expand Up @@ -190,10 +194,13 @@ def getLists(input, doPrintResults):
global hasFoundMatch
for item in filteredItems:
hasFoundMatch = True
wf3.add_item(title = item, valid = False,
wf3.add_item(
title = item,
valid = False,
#arg = 'cu ' + query.replace(input, '') + item + ' ',
autocomplete = query.replace(input, '') + item + ' ',
icon = './note.png')
icon = './note.png'
)
if doPrintResults and hasFoundMatch:
wf3.send_feedback()
else: # Even when nothing is entered, we need to fill our dictionaries.
Expand Down Expand Up @@ -319,12 +326,16 @@ def formatNotificationText(inputContent, inputDue, inputTags, inputPriority, ava
notificationBracketClose = ')'
if inputPriority != None and hasTags:
notificationSeparator = ', '
if inputDue and inputDue != 'None':
inputDue = emoji.emojize(':calendar:') + formatDate(inputDue)
else:
inputDue = ''

br = ''
if lineBreaks:
br = '\n'

return inputContent + (' ' if inputContent != '' else '') + br + emoji.emojize(':calendar:') + formatDate(inputDue) + notificationBracketOpen + notificationPriority + notificationSeparator + notificationTag + ' ' + (emoji.emojize(':spiral_notepad:') + str(next(iter(availableListsIdName))) if availableListsIdName != None else '') + notificationBracketClose
return inputContent + (' ' if inputContent != '' else '') + br + inputDue + notificationBracketOpen + notificationPriority + notificationSeparator + notificationTag + ' ' + (emoji.emojize(':spiral_notepad:') + str(next(iter(availableListsIdName))) if availableListsIdName != None else '') + notificationBracketClose


def formatDate(dateTime):
Expand Down Expand Up @@ -411,6 +422,7 @@ def getDueFromInput(query):
inputMinHourDayWeek = ''
passedDue = ''
isUseDefault = True
isNoDueDate = False
hasTime = len(query.split(' @', 2)) > 1
hasDefault = (getConfigValue(confNames['confDue']) != None and getConfigValue(confNames['confDue']) != '')
if hasTime or hasDefault:
Expand All @@ -426,19 +438,24 @@ def getDueFromInput(query):
passedDue = getConfigValue(confNames['confDue']) if isUseDefault else query.split(' @')[1][1:].split(' ')[0]
log.debug('passedDue: ' + str(passedDue))

inputMinHourDayWeek = getConfigValue(confNames['confDue'])[0] if isUseDefault else query.split(' @', 2)[1][0] # First character: m, h, d, w
inputMinHourDayWeek = ''
if (isUseDefault and getConfigValue(confNames['confDue'])):
inputMinHourDayWeek = getConfigValue(confNames['confDue'])[0]
elif len(query.split(' @', 2)[1]) > 0:
inputMinHourDayWeek = query.split(' @', 2)[1][0] # First character: m, h, d, w
if DEBUG > 1:
log.debug('inputMinHourDayWeek: ' + str(inputMinHourDayWeek))

isDefaultInteger = int(getConfigValue(confNames['confDue'])[1:])
isDefaultInteger = getConfigValue(confNames['confDue']) and int(getConfigValue(confNames['confDue'])[1:])
if hasTime:
isInputInteger = timeValue.isnumeric() #query.split(' @', 2)[1].strip()[1:].isnumeric()
if isUseDefault and isDefaultInteger:
inputDue = int(getConfigValue(confNames['confDue'])[1:])
elif isInputInteger:
inputDue = int(timeValue) #int(query.split(' @', 2)[1].strip()[1:])
else: # Invalid input
inputDue = 2
inputDue = 0 # No longer default of 2h - can now be set via configuration if desired, if not no due date will be added
isNoDueDate = True
inputMinHourDayWeek = 'h'

if inputMinHourDayWeek == 'm':
Expand All @@ -450,12 +467,16 @@ def getDueFromInput(query):
elif inputMinHourDayWeek == 'w':
inputDue *= 1000 * 60 * 60 * 24 * 7
else:
inputDue = 2 * 1000 * 60 * 60 # Default in 2 hours if no other value specified and no default context variable specified
inputDue = 0 # No longer default of 2h if no other value specified and no default context variable specified - can now be set via configuration if desired, if not no due date will be added
isNoDueDate = True
inputDue = datetime.datetime.now() + datetime.timedelta(milliseconds = inputDue) # Add to whatever buffer has been selected
if DEBUG > 1:
log.debug('inputDue: ' + str(inputDue))

return inputDue
if isNoDueDate:
return None
else:
return inputDue


def getListFromInput(query):
Expand Down Expand Up @@ -500,6 +521,7 @@ def getPriorityFromInput(query):

return inputPriority


def main(wf):
global query
# Check if there is a user input
Expand All @@ -519,10 +541,14 @@ def main(wf):
if DEBUG > 0:
log.debug('Attempted to define additional description.')
isDoNotDisplayCreate = True
wf3.add_item(title = 'Description already defined.', subtitle = 'Please remove the second \':\' defining a content.', valid = False,
wf3.add_item(
title = 'Description already defined.',
subtitle = 'Please remove the second \':\' defining a content.',
valid = False,
# arg = 'cu ' + query + ' ',
autocomplete = query + ' ',
icon = ICON_WARNING)
icon = ICON_WARNING
)
wf3.send_feedback()

# Evaluate input for labels
Expand Down Expand Up @@ -568,10 +594,14 @@ def main(wf):
if DEBUG > 0:
log.debug('Attempted to define additional priority.')
isDoNotDisplayCreate = True
wf3.add_item(title = 'Priority already defined.', subtitle = 'Please remove the second \'!\' defining a priority.', valid = False,
wf3.add_item(
title = 'Priority already defined.',
subtitle = 'Please remove the second \'!\' defining a priority.',
valid = False,
#arg = 'cu ' + query + ' ',
autocomplete = query + ' ',
icon = ICON_WARNING)
icon = ICON_WARNING
)
wf3.send_feedback()

# Evaluate input for lists
Expand Down Expand Up @@ -606,10 +636,14 @@ def main(wf):
if DEBUG > 0:
log.debug('Attempted to define additional list.')
isDoNotDisplayCreate = True
wf3.add_item(title = 'List already defined.', subtitle = 'Please remove the second \'+\' defining a list.', valid = False,
wf3.add_item(
title = 'List already defined.',
subtitle = 'Please remove the second \'+\' defining a list.',
valid = False,
# arg = 'cu ' + query + ' ',
autocomplete = query + ' ',
icon = ICON_WARNING)
icon = ICON_WARNING
)
wf3.send_feedback()

# Extract different parts from input
Expand All @@ -620,7 +654,6 @@ def main(wf):
inputList = getListFromInput(query)
inputPriority = getPriorityFromInput(query)


# Show 'Create Task' if user has completed their input - and no previous list item has been generated (JSON garbage).
inputEndsWithCommand = query[-2:] == ' #' or query[-2:] == ' !' or query[-2:] == ' +'
# log.debug('createListItemNotification - conditions: ')
Expand Down

0 comments on commit 18a1d55

Please sign in to comment.