Skip to content

Instantly share code, notes, and snippets.

@jesperes
Last active January 2, 2016 15:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jesperes/8321996 to your computer and use it in GitHub Desktop.
Save jesperes/8321996 to your computer and use it in GitHub Desktop.
Ruby script to check if you are eligible to log the "Know your local cacher". I've used in particular on http://coord.info/GC447Q2, but it should be easily adaptible to other similar caches. It will print a list of all cache owners of which you have logged at least three caches (of a certain) kind.
#
# Installation instructions for Nokogiri can be found at
# http://nokogiri.org/tutorials/installing_nokogiri.html
require 'nokogiri'
#
# Usage: ruby #{$0} /path/to/MyFinds.gpx
if ARGV.size == 0
puts "Usage: ruby #{$0} /path/to/MyFinds.gpx"
exit 1
end
xml = Nokogiri::XML(File.open(ARGV[0]))
ns = {
'gpx' => 'http://www.topografix.com/GPX/1/0',
'groundspeak' => "http://www.groundspeak.com/cache/1/0/1"
}
cachers = {}
xml.xpath("//groundspeak:cache", ns).each do |cache|
owner = cache.xpath("./groundspeak:owner", ns).text
type = cache.xpath("./groundspeak:type", ns).text
code = cache.parent.xpath("./gpx:name", ns).text
# This particular cache only allows certain caches
# to be counted towards the total.
if type == "Traditional Cache" or
type == "Unknown Cache" or
type == "Multi-cache"
if not cachers.has_key? owner
cachers[owner] = {}
end
cachers[owner][type] = code
end
end
n = 0
cachers.each_pair do |key, value|
if value.size >= 3
n = n + 1
puts "Cacher: #{key}"
value.each_pair do |type, code|
puts "#{type}: http://coord.info/#{code}"
end
end
end
if n >= 15
puts "Matches == #{n} (QUALIFIED)"
else
puts "Matches == #{n} (NOT QUALIFIED)"
puts "======"
puts "Candidates (2 caches)"
cachers.each_pair do |key, value|
if value.size == 2
puts "Cacher: #{key}"
value.each_pair do |type, code|
puts "#{type}: http://coord.info/#{code}"
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment