drompono Posted October 12, 2020 Share Posted October 12, 2020 Hi! Im using Simplenote and found out there is a CLI available. Now I want to create a workflow to search through my notes. I´m just starting to use the Script Filter more and still I don´t know how I can use json output from the cli to display the results in alfred. If I type something with the Script Filter: /usr/local/bin/sncli -n export {query} debugging shows me: ERROR: Simplenote Search[Script Filter] Unable to decode JSON results, top level type is not dictionary in JSON: [ { "tags": [], "deleted": false, "shareURL": "", "publishURL": "", "content": "gmail", "systemTags": [ "markdown" ], "modificationDate": 1599312951.145001, "creationDate": 1569875316, "key": "XXX", "version": 58, "syncdate": 1600667523.891809, "localkey": "XXX", "savedate": 1602487240.5917828 }, { "tags": [], "deleted": 0, "shareURL": "", "publishURL": "", "content": "gmail 2", "systemTags": [ "markdown" ], "modificationDate": 1587040951.0199919, "creationDate": 1587031436.520257, "key": "XXX", "version": 23, "syncdate": 1587154334.194783, "localkey": "XXX", "savedate": 1602487240.5917828 } ] How is it possible to create an item for each search result, for example with title: content, subtitle: creationDate, argument: localkey? Link to comment
deanishe Posted October 12, 2020 Share Posted October 12, 2020 36 minutes ago, drompono said: I don´t know how I can use json output from the cli to display the results in alfred You can't just directly feed any old JSON into Alfred: it requires a specific format. You need a script that decodes the Simplenote JSON, converts the data structure to one Alfred understands, then encodes that to JSON for Alfred. I don't have Simplenote, so I can't actually test this script, but it should be close to correct: #!/usr/bin/python import json import subprocess import sys def simple_search(query): """Search Simplenote via CLI.""" cmd = ['/usr/local/bin/sncli', '-n', 'export'] if query: cmd += [query] data = subprocess.check_output(cmd) return json.loads(data) def sn2alfred(results): """Convert sncli search results to Alfred results.""" items = [] for d in results: items.append({ 'title': d['content'], 'subtitle': d['modificationDate'], 'arg': d['key'] }) return items def main(): """Run script.""" query = sys.argv[1] if len(sys.argv) > 1 else '' items = sn2alfred(simple_search(query)) json.dump({'items': items}, sys.stdout) if __name__ == '__main__': main() Link to comment
drompono Posted October 12, 2020 Author Share Posted October 12, 2020 Fantastic! Thats working! One last question, the modificationDate in subtitle are in Unix Timestamp like 1587040951.0199919 - How can I convert them to %d.%m.% - %H:%M ? Link to comment
deanishe Posted October 12, 2020 Share Posted October 12, 2020 In Python: from datetime import datetime # where t = timestamp as a float dt = datetime.fromtimestamp(t) string_time = dt.strftime('%d.%m.%y - %H:%M') drompono 1 Link to comment
drompono Posted October 12, 2020 Author Share Posted October 12, 2020 thanks! items.append({ 'title': d['content'], 'subtitle': datetime.fromtimestamp(d['creationDate']).strftime('%d.%m.%y - %H:%M'), 'arg': d['localkey'] }) Link to comment
fazhan Posted April 29, 2022 Share Posted April 29, 2022 If you have problems working with simplenote, you can try other note taking apps: https://www.xp-pen.com/forum-5583.html I'm quite happy with Google Keep- use it across devices etc. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now