Skip to content

Commit

Permalink
Support set search folder
Browse files Browse the repository at this point in the history
more friendly hints
Fix unicode display issue
  • Loading branch information
XericWei committed Mar 8, 2018
1 parent a3fbc81 commit a8ba933
Show file tree
Hide file tree
Showing 5 changed files with 222 additions and 119 deletions.
111 changes: 87 additions & 24 deletions conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@
import re

from workflow import Workflow
from consts import *

log = None

KEY_PAGE_SIZE = 'pagesize'
ALL_KEYS = [KEY_PAGE_SIZE]

def main(wf):
query = sys.argv[1]
log.info(query)
Expand All @@ -20,33 +18,98 @@ def main(wf):

def handle(query):
query = unicode(query, 'utf-8')
query = query.strip()

if re.match(r'\S+\s+\S+', query) is None:
return

query.replace(r'\s+', ' ')
kvPair = query.split(' ')

key = kvPair[0]
val = kvPair[1]

message = None
if ALL_KEYS.index(key) >= 0:
# wf.store_data(key, val)
# message = 'Configure ' + key + ' to ' + val + 'successfully!'
arg = key + ' ' + val
wf.add_item(
title='Set query page size to ' + val,
subtitle='',
arg=arg,
uid=arg,
valid=True
)
hasOption = False
for i, key in enumerate(ALL_KEYS):
if key.startswith(query):
if query == KEY_FOLDER:
hasOption = True
prepareFolders()
else:
hasOption = True
option = key + ' ' + ALL_VALS[i]
wf.add_item(
title=option,
subtitle='',
arg=option,
uid=option,
valid=False
)
if not hasOption:
option = 'You can configure: ' + ', '.join(ALL_KEYS)
wf.add_item(
title=option,
subtitle='',
arg=option,
uid=option,
valid=False
)
else:
message = 'Unrecognize configuration name: ' + key
query.replace(r'\s+', ' ')
kvPair = query.split(' ')

key = kvPair[0]
val = kvPair[1]

message = None
if ALL_KEYS.index(key) >= 0:
# wf.store_data(key, val)
# message = 'Configure ' + key + ' to ' + val + 'successfully!'
arg = key + ' ' + val
wf.add_item(
title='Set ' + ALL_KEY_DESCS[ALL_KEYS.index(key)] + ' to ' + val,
subtitle='',
arg=arg,
uid=arg,
valid=True
)
else:
message = 'Unrecognize configuration name: ' + key

wf.send_feedback()

def prepareFolders():
import sqlite3

#add default folder
wf.add_item(
title='Default(All)',
subtitle='Set search folder under Default(All)',
valid=True,
uid='folder 0',
arg='folder 0',
)

homePath = os.environ['HOME']

# outlookData = homePath + '/outlook/'
outlookData = homePath + OUTLOOK_DATA_PATH

con = sqlite3.connect(outlookData + 'Outlook.sqlite')
count = 0
cur = con.cursor()

log.info("start querying folders")
cur.execute( """
SELECT Record_RecordID, Folder_Name FROM Folders
WHERE Record_AccountUID > 0
AND Folder_Name is not null
""")

if cur.rowcount:
for row in cur:
log.info(row[1])
wf.add_item(
title=unicode(row[1]),
subtitle='Set search folder under ' + unicode(row[1]),
valid=True,
uid='folder ' + str(row[0]),
arg='folder ' + str(row[0]),
)

cur.close()

if __name__ == '__main__':
wf = Workflow()
Expand Down
11 changes: 11 additions & 0 deletions consts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#coding:utf-8
PAGE_SIZE = 20
OUTLOOK_DATA_PATH = r'/Library/Group Containers/UBF8T346G9.Office/Outlook/Outlook 15 Profiles/Main Profile/Data/'

KEY_PAGE_SIZE = 'pagesize'
KEY_FOLDER = 'folder'
ALL_KEYS = [KEY_PAGE_SIZE, KEY_FOLDER]
ALL_KEY_DESCS = ['one page result size', 'search folder']
ALL_VALS = ['[number]', '[folder name]']

RULES = [r'pagesize \d+', r'folder \d+']
50 changes: 25 additions & 25 deletions info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -241,31 +241,6 @@ python main.py "$query"</string>
<key>version</key>
<integer>1</integer>
</dict>
<dict>
<key>config</key>
<dict>
<key>concurrently</key>
<false/>
<key>escaping</key>
<integer>102</integer>
<key>script</key>
<string>query=$1
python setconf.py "$query"</string>
<key>scriptargtype</key>
<integer>1</integer>
<key>scriptfile</key>
<string></string>
<key>type</key>
<integer>0</integer>
</dict>
<key>type</key>
<string>alfred.workflow.action.script</string>
<key>uid</key>
<string>0B63B674-D674-4D94-B97A-9D8122956F48</string>
<key>version</key>
<integer>2</integer>
</dict>
<dict>
<key>config</key>
<dict>
Expand Down Expand Up @@ -315,6 +290,31 @@ python conf.py "$query"</string>
<key>version</key>
<integer>2</integer>
</dict>
<dict>
<key>config</key>
<dict>
<key>concurrently</key>
<false/>
<key>escaping</key>
<integer>102</integer>
<key>script</key>
<string>query=$1
python setconf.py "$query"</string>
<key>scriptargtype</key>
<integer>1</integer>
<key>scriptfile</key>
<string></string>
<key>type</key>
<integer>0</integer>
</dict>
<key>type</key>
<string>alfred.workflow.action.script</string>
<key>uid</key>
<string>0B63B674-D674-4D94-B97A-9D8122956F48</string>
<key>version</key>
<integer>2</integer>
</dict>
<dict>
<key>config</key>
<dict>
Expand Down
Loading

0 comments on commit a8ba933

Please sign in to comment.