From b9c2399669629bba9da5d164a553181ee565a9da Mon Sep 17 00:00:00 2001 From: Michal Duda Date: Sat, 19 Oct 2019 18:43:53 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A9Code:=20Fix=20retrieval=20of=20mult?= =?UTF-8?q?iple=20sets=20of=20gists?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + src/info.plist | 272 ++++++++++++++++++++++++------------------------- 2 files changed, 132 insertions(+), 141 deletions(-) diff --git a/.gitignore b/.gitignore index 7bbc71c..40f12af 100644 --- a/.gitignore +++ b/.gitignore @@ -99,3 +99,4 @@ ENV/ # mypy .mypy_cache/ +.DS_Store diff --git a/src/info.plist b/src/info.plist index 7ac0dd6..0be227b 100644 --- a/src/info.plist +++ b/src/info.plist @@ -12,33 +12,31 @@ destinationuid - E521D56F-09F3-4F56-8516-9C81673431F4 + F5FD00A5-9BC1-4219-9F4C-BBCACBBA3D77 modifiers 0 modifiersubtext + sourceoutputuid + 2E4C73AB-0D31-49F5-9FC6-25AAC21FDD7E vitoclose - - 3D83604F-42DF-4921-B9E7-946F833B4CEA - destinationuid - D0EC2969-05DA-4F50-85FB-BCEDF222196C + 10BF19E8-25C0-4D4B-8AF4-1910DEDB15A1 modifiers 0 modifiersubtext + sourceoutputuid + 3AC5A510-EDC4-4448-925A-523021E79B10 vitoclose - - 90DF95FE-FD71-4D95-9DEF-374E3FFF9C8C - destinationuid - F5FD00A5-9BC1-4219-9F4C-BBCACBBA3D77 + E521D56F-09F3-4F56-8516-9C81673431F4 modifiers 0 modifiersubtext @@ -47,21 +45,11 @@ - 9F1EBFFB-363A-481D-AA5C-3489DE9794BC + 3D83604F-42DF-4921-B9E7-946F833B4CEA destinationuid - F1232220-E014-4916-AC8B-3A03E133F257 - modifiers - 0 - modifiersubtext - - vitoclose - - - - destinationuid - 90DF95FE-FD71-4D95-9DEF-374E3FFF9C8C + D0EC2969-05DA-4F50-85FB-BCEDF222196C modifiers 0 modifiersubtext @@ -69,6 +57,9 @@ vitoclose + + 9F1EBFFB-363A-481D-AA5C-3489DE9794BC + destinationuid 3A2F0E29-2F86-4310-ABF2-0C40465E43FD @@ -112,6 +103,8 @@ 0 modifiersubtext + sourceoutputuid + 5494B886-C269-45A9-9AC5-C30F6BB2BBA6 vitoclose @@ -155,24 +148,11 @@ - F1232220-E014-4916-AC8B-3A03E133F257 - - - destinationuid - 10BF19E8-25C0-4D4B-8AF4-1910DEDB15A1 - modifiers - 0 - modifiersubtext - - vitoclose - - - createdby Michal Duda description - Alfred 3 workflow for opening your GitHub Gists in your default browser. + Alfred 4 workflow for opening your GitHub Gists in your default browser. disabled name @@ -189,33 +169,14 @@ removeextension text - Personal Token hasn't been set yet + Username hasn't been set yet! title GitHub Gists type alfred.workflow.output.notification uid - 10BF19E8-25C0-4D4B-8AF4-1910DEDB15A1 - version - 1 - - - config - - inputstring - {query} - matchcasesensitive - - matchmode - 0 - matchstring - /token-not-set^^^ - - type - alfred.workflow.utility.filter - uid - F1232220-E014-4916-AC8B-3A03E133F257 + F5FD00A5-9BC1-4219-9F4C-BBCACBBA3D77 version 1 @@ -229,33 +190,58 @@ removeextension text - Username hasn't been set yet + Personal Token hasn't been set yet! title GitHub Gists type alfred.workflow.output.notification uid - F5FD00A5-9BC1-4219-9F4C-BBCACBBA3D77 + 10BF19E8-25C0-4D4B-8AF4-1910DEDB15A1 version 1 config - inputstring - {query} - matchcasesensitive - - matchmode - 0 - matchstring - /user-not-set^^^ + conditions + + + inputstring + + matchcasesensitive + + matchmode + 0 + matchstring + /user-not-set^^^ + outputlabel + user not set + uid + 2E4C73AB-0D31-49F5-9FC6-25AAC21FDD7E + + + inputstring + + matchcasesensitive + + matchmode + 0 + matchstring + /token-not-set^^^ + outputlabel + token ot set + uid + 3AC5A510-EDC4-4448-925A-523021E79B10 + + + elselabel + no error type - alfred.workflow.utility.filter + alfred.workflow.utility.conditional uid - 90DF95FE-FD71-4D95-9DEF-374E3FFF9C8C + 3A2F0E29-2F86-4310-ABF2-0C40465E43FD version 1 @@ -293,6 +279,8 @@ sys.stdout.write(cache) alfredfiltersresultsmatchmode 0 + argumenttreatemptyqueryasnil + argumenttrimmode 0 argumenttype @@ -312,28 +300,60 @@ sys.stdout.write(cache) script #!/usr/bin/python +######################################################### +# License: GPLv3 +# Author: Michal Duda <github@vookimedlo.cz> +# Home: https://github.com/vookimedlo/alfred-github-gists +# Project: alfred-github-gist +# +######################################################### + +import Queue +import base64 import io import json import os import re import sys -import base64 import urllib2 query = "{query}" queryPattern = re.compile(query, re.I) -user = os.getenv('user') +user = os.getenv('user') token = os.getenv('personalToken') cache = os.getenv('cache') # Just a very simple caching # if os.path.isfile(cache) and os.path.getsize(cache) == 0: - url = 'https://api.github.com/users/' + user + '/gists' + data = [] + url = 'https://api.github.com/users/' + user + '/gists' auth = {'Authorization': 'Basic ' + base64.b64encode(user + ':' + token)} - response = urllib2.urlopen(urllib2.Request(url, headers=auth)).read() - data = json.loads(response) + + linkPattern = re.compile('<(https://[^>]+)>\s*;\s*rel="next"') + + queue = Queue.Queue() + queue.put(url) + + while not queue.empty(): + queuedUrl = queue.get() + response = urllib2.urlopen(urllib2.Request(queuedUrl, headers=auth)) + header = response.info() + content = response.read() + partialData = json.loads(content) + + # Join multiple json data + # + for i in xrange(0, len(partialData)): + data.append(partialData[i]) + + if 'link' in header.dict: + link = header.dict['link'] + result = linkPattern.search(link) + if result: + queue.put(result.group(1)) + with io.open(cache, 'w', encoding='utf8') as cacheFile: dumpedData = json.dumps(data, ensure_ascii=False) cacheFile.write(unicode(dumpedData)) @@ -341,6 +361,8 @@ else: with io.open(cache, 'r', encoding='utf8') as cacheFile: data = json.loads(cacheFile.read()) +# Alfred menu items +# alfreditems = {"items": []} for item in data: @@ -354,8 +376,6 @@ for item in data: icon = "gist.png" if item["public"] else "gist-secret.png" - # Alfred menu items - # alfreditems['items'].append({ "mysortkey": mysortkey, "uid": title, @@ -380,7 +400,7 @@ sys.stdout.write(dump) scriptfile subtext - Shows your gists and opens them in WebBrowser + Shows your gists and opens them in a WebBrowser title Github Gists type @@ -393,7 +413,7 @@ sys.stdout.write(dump) uid 3D83604F-42DF-4921-B9E7-946F833B4CEA version - 2 + 3 config @@ -497,35 +517,28 @@ echo -n "{query}" config - argument + conditions + + + inputstring + + matchcasesensitive + + matchmode + 4 + matchstring + ^http + outputlabel + no error + uid + 5494B886-C269-45A9-9AC5-C30F6BB2BBA6 + + + elselabel - variables - - cache - {query} - - - type - alfred.workflow.utility.argument - uid - A48F8F7F-629E-4938-94B6-3B64978B32F5 - version - 1 - - - config - - inputstring - {query} - matchcasesensitive - - matchmode - 2 - matchstring - ^http type - alfred.workflow.utility.filter + alfred.workflow.utility.conditional uid C3E506E4-3A41-423D-ABDD-2E35BF9DC87E version @@ -534,19 +547,18 @@ echo -n "{query}" config - inputstring - {query} - matchcasesensitive - - matchmode - 0 - matchstring + argument + variables + + cache + {query} + type - alfred.workflow.utility.filter + alfred.workflow.utility.argument uid - 3A2F0E29-2F86-4310-ABF2-0C40465E43FD + A48F8F7F-629E-4938-94B6-3B64978B32F5 version 1 @@ -659,7 +671,7 @@ Icons taken from https://octicons.github.com/ - MIT License xpos 630 ypos - 40 + 175 3A2F0E29-2F86-4310-ABF2-0C40465E43FD @@ -668,9 +680,9 @@ Icons taken from https://octicons.github.com/ - MIT License note GitHubGists - check for error xpos - 510 + 425 ypos - 370 + 180 3D83604F-42DF-4921-B9E7-946F833B4CEA @@ -705,17 +717,6 @@ Icons taken from https://octicons.github.com/ - MIT License ypos 520 - 90DF95FE-FD71-4D95-9DEF-374E3FFF9C8C - - colorindex - 1 - note - GitHubGists - check for error - xpos - 510 - ypos - 220 - 9F1EBFFB-363A-481D-AA5C-3489DE9794BC colorindex @@ -745,9 +746,9 @@ Icons taken from https://octicons.github.com/ - MIT License note GitHubGists - check url xpos - 1290 + 1280 ypos - 370 + 360 D0EC2969-05DA-4F50-85FB-BCEDF222196C @@ -782,17 +783,6 @@ Icons taken from https://octicons.github.com/ - MIT License ypos 340 - F1232220-E014-4916-AC8B-3A03E133F257 - - colorindex - 1 - note - GitHubGists - check for error - xpos - 510 - ypos - 70 - F5FD00A5-9BC1-4219-9F4C-BBCACBBA3D77 colorindex @@ -802,7 +792,7 @@ Icons taken from https://octicons.github.com/ - MIT License xpos 630 ypos - 190 + 10 variables @@ -820,7 +810,7 @@ Icons taken from https://octicons.github.com/ - MIT License user version - 2018.10.14 + 2019.10.19 webaddress https://github.com/vookimedlo/alfred-github-gists