Uproar Gits
Uproar has made its home at GitHub. The project is ripe for the taking, and there’s a vague Roadmap in the wiki, for the things I want to do with it. I’ll be hopefully making some updates to it this week. Enjoy!
Uproar has made its home at GitHub. The project is ripe for the taking, and there’s a vague Roadmap in the wiki, for the things I want to do with it. I’ll be hopefully making some updates to it this week. Enjoy!
Here we go: http://www.ardekantur.com/misc/uproar/ - the perfect spot for a tiny lil piece of code like Uproar. Updates will come frequently, as I’m now using it daily. The output of search results has changed a little bit to make it more digestable.
Rather than sleep, I’ve decided to improve (read: radically bloat) uproar.rb.
uproar.rb
# uproar.rb - search a YAML-encoded list of links for matching tags # ardekantur.com %w[ rubygems yaml open-uri hpricot ].each { |x| require x } def set_option hash, name, default i = ARGV.index(name) hash[name] = i ? ARGV[i + 1] : default end def search_tags file, tag links = File.open( file ) db = [] YAML::load_documents( links ) { |doc| db << doc } matches = [] db.each { |l| matches << l if l['tags'].include? tag } matches.each { |l| printf "%30s... - %s\n", l['title'][0..30], l['link'] } end def add_link file, address, tags doc = Hpricot(open(address)) title = doc.at("title").inner_html.strip puts "Adding '#{title}' to #{file}..." links = File.new( file, "a" ) links.puts "\n---" links.puts "title: '#{title.gsub(/'/, '\'\'')}'" links.puts "link: #{address}" tags = tags ? tags.strip.gsub(/ /, ', ') : '' links.puts "tags: [#{tags}]" links.close end o = {} set_option o, '-s', nil set_option o, '-f', 'Links.yaml' set_option o, '-t', '' set_option o, '-a', nil raise "please specify either a tag to search for or a link to add." if (!o['-s'] and !o['-a']) or (o['-s'] and o['-a']) search_tags o['-f'], o['-s'] if o['-s'] add_link o['-f'], o['-a'], o['-t'] if o['-a']
New functionality! Specify your links file with -f filename.yaml. Searching with tags now uses -s tag instead of -t tag. Adding a link works like this: ruby Uproar.rb -a http://webaddress.com/ -t "space separated list of tags". The title is grabbed automagically for you :)
I use del.icio.us, but I don’t like the idea that I don’t have control of the server, so if something happens to my bookmarks, I’m screwed. I also want more universal integration of my bookmarks with all the browsers I used - from Lynx to Opera. So I wrote some Ruby.
delicious-to-yaml.rb
require 'rubygems' require 'hpricot' doc = open("links.html") { |f| Hpricot(f) } (doc/"a").each do |link| puts "---" puts "title: '#{link.inner_html.gsub(/'/, '\'\'')}'" puts "link: #{link.attributes['href']}" tags = link.attributes['tags'] ? link.attributes['tags'].gsub(/,/, ', ') : '' puts "tags: [#{tags}]" end
Go to https://secure.del.icio.us/settings/<your delicious username>/bookmarks/export - uncheck ‘include my notes’, but keep ‘include my tags’ checked. Save the result to links.html, then run the code above in the same directory as links.html. Pipe the output to another file, like Links.yaml. This is your new bookmark repository. Each link is a separate document, like the following:
--- title: 'I speak dog » Using GnuPG encyption with Mac OS X Mail' link: http://www.wasuvi.com/?page_id=2368 tags: [apple, howto, osx, gpg, security, email, toread] --- title: 'All recipes – complete resource for recipes and cooking tips' link: http://allrecipes.com/ tags: [recipes, howto, health, toread]
So on, so forth. This is obviously very human readable - you can simply add new links to the file by typing them in yourself. The next step is a file which asks for a tag and gives you the links that are tagged with it:
uproar.rb
require 'yaml' def set_option hash, name, default i = ARGV.index(name) raise "no argument specified" unless i hash[name] = default and return unless i raise "no argument specified: #{name}" if(ARGV.length <= i) hash[name] = ARGV[i + 1] end o = {} set_option o, '-t', nil raise "please specify a tag." if o['-t'] == nil links = File.open( 'Links.yaml' ) db = [] YAML::load_documents( links ) { |doc| db << doc } matches = [] db.each { |l| matches << l if l['tags'].include? o['-t'] } matches.each { |l| printf "%30s... - %s\n", l['title'][0..30], l['link'] }
It’s a little ugly right now, but it does what it’s supposed to do. That is Uproar.
Possible Improvements