Skip to content
This repository has been archived by the owner on Sep 24, 2022. It is now read-only.

Improve Alfred workflow #127

Closed
wants to merge 1 commit into from
Closed

Conversation

huguesbr
Copy link

Allow to list all API directly and eventually filter it.

Usage:
dev y will show dev Youtube.
dev resync will rebuild local copy of sites.json to build listing.

@huguesbr
Copy link
Author

huguesbr commented Nov 4, 2015

@nquinlan I think the build is broken higher in the branch. any chance you can give me your feeling about the alfred extension improvement?

it's using ruby to generate an extension filter in order to present the dev matching the query..

it look like this:

#!/usr/bin/env ruby
require 'net/http'
require "json"

filter = ARGV[0]
path = "./tmp/sites.xml"

def check_file_list_cache(path, url)
  if !File.exists?(path)
    f = File.new(path, "w")
    response = Net::HTTP.get(url,"/sites.json")
    f.puts response
    f.close
  end
end

def load_sites(path, filter)
  json = File.read(path)
  data = JSON.parse(json, symbolize_names: true)
  sites = data[:sites]
  sites = sites.select do |s|
    /#{filter}/i.match(s[:name])
  end if !filter.nil?
  sites
end

def xml_list(sites)
  print "<?xml version=\"1.0\"?>"
  print "\t<items>\n"
  sites.each do |site|
    print "\t\t<item arg=\"#{site[:shortcuts][0]}\" autocomplete=\"#{site[:name]}\">"
    print "\t\t\t<title>#{site[:name]}</title>"
    print "\t\t</item>"
  end
  print "\t</items>"
end

check_file_list_cache(path, "devcenter.me")
sites = load_sites(path, ARGV[0])
xml_list(sites)

Without any filter, just present the list
improve_alfred_workflow_by_huguesbr_ _pull_request__127_ _stevestreza_devcenter_me

Start typing and it filter the list
improve_alfred_workflow_by_huguesbr_ _pull_request__127_ _stevestreza_devcenter_me

@huguesbr
Copy link
Author

@stevestreza any change you could review this?

1 similar comment
@huguesbr
Copy link
Author

huguesbr commented Apr 1, 2016

@stevestreza any change you could review this?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants