def act(): args = alp.args() if args[0] == "configure": url = args[1] sig = args[2] s = alp.Settings() s_dict = {"url": url} s.set(**s_dict) kc = alp.Keychain("yourls_stats") if not kc.retrievePassword("signature"): kc.storePassword("signature", sig) else: kc.modifyPassword("signature", sig) info = alp.readPlist(alp.local("info.plist")) objs = info['objects'] kw = None for o in objs: if o['type'] == "alfred.workflow.input.scriptfilter": kw = o['config']['keyword'] break if kw: scpt = "tell application \"Alfred 2\" to search \"{0}\"".format(kw) call(["osascript", "-e", scpt]) print "Yourls Configured" elif args[0] == "copy": print args[1]
def search_for(query): results = [] s = alp.Settings() country = s.get("country", "US") args = { 'term': query, 'country': country, 'media': 'all', "entity": "allTrack", 'attribute': 'allTrackTerm', 'limit': '10' } its_api = "http://itunes.apple.com/search" myScraper = alp.Request(its_api, args) theResult = myScraper.request.json() results.extend(theResult["results"]) args = { 'term': query, 'country': country, 'media': 'all', 'entity': 'allArtist', 'attribute': 'allArtistTerm', 'limit': '10' } r = alp.Request(its_api, args) results.extend(r.request.json()["results"]) return results
def search_for(query): s = alp.Settings() country = s.get("country", "US") args = { 'term': query, 'country': country, 'media': 'software', 'limit': '10' } its_api = "http://itunes.apple.com/search" myScraper = alp.Request(its_api, args) theResult = myScraper.request.json() return theResult['results']
def resultParse(item): iconLoc = artworkCache(item['artworkUrl60']) itemID = item['trackId'] directLink = "itms://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=%s&mt=8" % ( itemID) s = alp.Settings() if s.get("affiliate_string", None): directLink += s.get("affiliate_string") return { 'uid': item['trackName'], 'arg': directLink, 'title': item['trackName'], 'subtitle': u"by %s\u2014%s" % (item['artistName'], item['formattedPrice']), 'icon': iconLoc, 'valid': True }
def resultParse(item): try: i = item['artworkUrl30'] iconLoc = artworkCache(item['artworkUrl30']) except KeyError: iconLoc = "icon.png" try: viewURL = item['trackViewUrl'] except KeyError: try: viewURL = item['artistLinkUrl'] except KeyError: viewURL = item['artistViewUrl'] try: title = item['trackName'] subtitle = u"by %s\u2014$%s" % (item['artistName'], item['trackPrice']) except KeyError: title = item['artistName'] try: subtitle = u"%s\u2014%s" % (item['artistType'], item['primaryGenreName']) except KeyError: try: subtitle = item['artistType'] except KeyError: subtitle = "" directLink = "itms" + viewURL[5:] s = alp.Settings() if s.get("affiliate_string", None): directLink += s.get("affiliate_string") return { # 'uid': item['trackName'], 'arg': directLink, 'title': title, 'subtitle': subtitle, 'icon': iconLoc, 'valid': True }
import alp try: path = alp.args()[0] if path == "auto": path = "" s = alp.Settings() s.set(**{"budget_path": path}) if path == "": print "YNAB budget path set to automatic" else: print "YNAB budget path set to %s" % path except Exception, e: alp.log("Oh no, an exception while saving configuration:", e)
def do_feedback(): storedNames = alp.jsonLoad("files.json", default=[]) s = alp.Settings() defaultExt = s.get("extension", ".txt") args = alp.args()[0] args = args.split(" ") if len(args) == 1 and args[0] == "": empty = [] if len(storedNames) > 0: for name in storedNames: empty.append( I(uid=name, valid=True, autocomplete=name, title=name, subtitle="Create {0} in frontmost Finder window.".format( name), arg="touch \"{0}\"".format(name))) empty.append( I(title="Add Filename", subtitle="Store a filename for faster access", autocomplete="|add| ", valid=False)) empty.append( I(title="Add Path", subtitle="Store a path for use with 'touch filename at'", autocomplete="|path| ", valid=False)) alp.feedback(empty) elif args[0] == "|add|": if len(args) >= 2: name = " ".join(args[1:]) else: name = "" if not "." in name: name += defaultExt alp.feedback( I(title="Store Filename", subtitle="Store {0} for faster access".format(name), arg="add \"{0}\"".format(name), valid=True)) elif args[0] == "|path|": if len(args) >= 2: name = " ".join(args[1:]) else: name = "" alp.feedback( I(title=name, subtitle="Store {0} as a location for new files".format(name), arg="path \"{0}\"".format(name), valid=True)) elif "at" in args: i = args.index("at") name = args[:i] name = " ".join(name) if not "." in name: name += defaultExt feedback = [] storedPaths = alp.jsonLoad("paths.json", default=[]) if len(storedPaths) > 0: for path in storedPaths: (_, tail) = os.path.split(path) touch_path = os.path.join(path, name) feedback.append( I(title="...{0}/{1}".format(tail, name), subtitle="{0}{1}".format(path, name), arg="at \"{0}\"".format(touch_path), valid=True)) else: feedback.append( I(title="No saved paths!", subtitle="Store a path to use this feature.", valid=False)) alp.feedback(feedback) else: name = " ".join(args) if not "." in name: name += defaultExt alp.feedback( I(title=name, subtitle="Create {0} in frontmost finder window.".format(name), valid=True, arg="touch \"{0}\"".format(name), uid=name))
def do_feedback(): args = alp.args() settings = alp.Settings() url = settings.get("url", None) if url: k = alp.Keychain("yourls_stats") sig = k.retrievePassword("signature") links = fetch_stats(url, sig) if isinstance(links, I): alp.feedback(links) return feedback = [] def build_feedback(good_links): for l in good_links: s = "" if int(l["clicks"]) == 1 else "s" subtitle = u"{0} \u2022 {1} click{2}".format( l["shorturl"], l["clicks"], s) feedback.append( I(title=l["title"], subtitle=subtitle, valid=True, arg="copy \"{0}\"".format(l["shorturl"]))) if len(args) == 0 and url: build_feedback(links) elif len(args): q = args[0] if "!" in q: links = fetch_stats(url, sig, force=True) if isinstance(links, I): alp.feedback(links) return q = q.replace("!", "") if not url or "=" in q: new_settings = q.split(" ") url = "foo" sig = "bar" for ns in new_settings: if "=" in ns: k = ns.split("=")[0] v = ns.split("=")[1] if k == "url": if not v.startswith("http://"): v = "http://" + v if v.endswith("php"): pass elif v.endswith("/"): v += "yourls-api.php" else: v += "/yourls-api.php" url = v if k == "signature": sig = v valid = True if "=" in q and (url != "foo") and ( sig != "bar") else False feedback = I(title="Configure Yourls", subtitle="url={0} signature={1}".format(url, sig), valid=valid, arg="configure \"{0}\" \"{1}\"".format(url, sig)) elif url: gl = alp.fuzzy_search( q, links, key=lambda x: u"{0} - {1}".format(x["title"], x["shorturl"])) build_feedback(gl) if len(feedback) == 0: feedback = I(title="No Results", subtitle="No Yourls matched your query.", valid=False) else: feedback = I(title="Configure Yourls", subtitle="url=foo signature=bar", valid=False) alp.feedback(feedback)