-
Notifications
You must be signed in to change notification settings - Fork 0
/
exclude_myfinds_tomtom_route.rb
executable file
·77 lines (63 loc) · 1.3 KB
/
exclude_myfinds_tomtom_route.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/ruby
require 'csv'
require 'nokogiri'
def parse_myfinds(doc)
doc.root.elements.each do |node|
parse_wpt(node)
end
end
def parse_wpt(node)
if node.node_name.eql? 'wpt'
node.elements.each do |node|
parse_gccode(node)
end
end
end
def parse_gccode(node)
if node.node_name.eql? 'name'
#puts "MY: " + node.text.to_s
@myfinds << node.text.to_s
end
end
def parse_csv(csv)
csv.each do |row|
#puts "CSV: " + row[2]
@caches << row[2]
end
end
def parse_csv_tomtom(csv)
csv.each do |row|
unless already_found(row[2])
puts row[0] + "|" + row[1] + "|" + row[2] + "|" + row[3] + "|"
end
end
end
def already_found(gccode)
@myfinds.each do |find|
if find.eql? gccode
return true
end
end
return false
end
def output_notfound
@notfound = @caches - @myfinds
@notfound.each do |cache|
#puts "NOT: " + cache.to_s
puts cache.to_s
end
end
@myfinds = Array.new
@caches = Array.new
@notfound = Array.new
# open and parse myfinds gpx file
my = Nokogiri::XML(File.open("6086044.gpx"))
parse_myfinds(my)
# open and parse csv file
csvFile = File.read('route.csv')
csv = CSV.parse(csvFile, :headers => false, :col_sep => '|')
#parse_csv(csv)
# parse and output tomtom file
parse_csv_tomtom(csv)
# output the notfound caches
#output_notfound