diff --git a/machMateKate.rb b/machMateKate.rb
index 4ca6a7f..92652c0 100755
--- a/machMateKate.rb
+++ b/machMateKate.rb
@@ -49,21 +49,16 @@
$do_download = true
end
-# Flag, show or hide drink_xyz elements
+# Flag, show or hide drink:...=no elements
$show_drink_no = false;
# URLs, file names and counters
-$URL_drink_club_mate="http://www.overpass-api.de/api/xapi?node[drink:club-mate=*]"
-$XML_drink_club_mate="drink_club-mate.xml"
-$TXT_drink_club_mate="drink_club-mate.txt"
-$count_drink_club_mate = 0;
-$date_drink_club_mate = "";
-
-$URL_drink_afri_cola="http://www.overpass-api.de/api/xapi?node[drink:afri-cola=*]"
-$XML_drink_afri_cola="drink_afri-cola.xml"
-$TXT_drink_afri_cola="drink_afri-cola.txt"
-$count_drink_afri_cola = 0;
-$date_drink_afri_cola = "";
+$drinks = ['club-mate', 'afri-cola']
+$URL_template = "http://www.overpass-api.de/api/xapi?##OBJECT##[drink:##DRINK##=*]"
+$FILE_template = "drink_##DRINK##.##EXT##"
+$count = Hash.new();
+$date = Hash.new();
+$icons = Hash.new();
# HTML file generation
$html_infile = "matekate.html.in"
@@ -74,6 +69,23 @@
# Helper functions
################################
+# Initializes some structures.
+# count, date and icon hashes are filled with initial content.
+# Icons for different drinks/drinkvalues must have same size for this to work fine.
+def init()
+ $drinks.each do | drink |
+ $count[drink] = 0
+ $date[drink] = ""
+ iconsdrink = Hash.new();
+ iconsdrink["retail"] = "./icon_" + drink + "-retail_30x40_-12x-28.png\t30,40\t-12,-28"
+ iconsdrink["served"] = "./icon_" + drink + "-served_32x40_-12x-28.png\t32,40\t-12,-28"
+ iconsdrink["no"] = "./icon_" + drink + "-no_24x24_-12x-12.png\t24,24\t-12,-12"
+ iconsdrink["default"] = "./icon_" + drink + "_24x24_-12x-12.png\t24,24\t-12,-12"
+ $icons[drink] = iconsdrink;
+
+ end
+end
+
# Download data (max. 3 tries)
#
# Give an URL and under which name the data shall be stored.
@@ -208,37 +220,25 @@ def parse(infile, outfile, drink_tag, description_extra, icons)
end
-###########################
-# tag: drink:club-mate=*
-###########################
-
-# download
-download($URL_drink_club_mate, $XML_drink_club_mate)
-
-icons = Hash.new()
-icons["retail"] = "./icon_club-mate-retail_30x40_-12x-28.png\t30,40\t-12,-28"
-icons["served"] = "./icon_club-mate-served_32x40_-12x-28.png\t32,40\t-12,-28"
-icons["no"] = "./icon_club-mate-no_24x24_-12x-12.png\t24,24\t-12,-12"
-icons["default"] = "./icon_club-mate_24x24_-12x-12.png\t24,24\t-12,-12"
-$count_drink_club_mate, $date_drink_club_mate =
- parse($XML_drink_club_mate, $TXT_drink_club_mate, "drink:club-mate", "", icons)
-
+#################################
+# Initialize data
+#################################
-###########################
-# tag: drink:afri-cola=*
-###########################
+init();
-# Download data
-download($URL_drink_afri_cola, $XML_drink_afri_cola)
+#################################
+# tag: drink:[name of drink]=*
+#################################
-icons = Hash.new()
-icons["retail"] = "./icon_afri-cola-retail_30x40_-12x-28.png\t30,40\t-12,-28"
-icons["served"] = "./icon_afri-cola-served_32x40_-12x-28.png\t32,40\t-12,-28"
-icons["no"] = "./icon_afri-cola-no_24x24_-12x-12.png\t24,24\t-12,-12"
-icons["default"] = "./icon_afri-cola_24x24_-12x-12.png\t24,24\t-12,-12"
-$count_drink_afri_cola, $date_drink_afri_cola =
- parse($XML_drink_afri_cola, $TXT_drink_afri_cola, "drink:afri-cola", "", icons)
+$drinks.each do | drink |
+ download($URL_template.gsub("##DRINK##", drink).gsub("##OBJECT##", "node"), $FILE_template.gsub("##DRINK##", drink).gsub("##EXT##", "xml"))
+ countdrink, datedrink =
+ parse($FILE_template.gsub("##DRINK##", drink).gsub("##EXT##", "xml"),
+ $FILE_template.gsub("##DRINK##", drink).gsub("##EXT##", "txt"), "drink:" + drink, "", $icons[drink])
+ $count[drink] = countdrink;
+ $date[drink] = datedrink;
+end
###########################
@@ -247,11 +247,10 @@ def parse(infile, outfile, drink_tag, description_extra, icons)
#
# We read a html file and substitute the following patterns:
#
-# ##count_drink_afri_cola## => number of afri-cola nodes
-#
-# ##count_drink_club_mate## => number of club nodes (new tag)
-#
-# ##count_club_mate## => number of club nodes (old tag)
+# ##count_drink_afri-cola## => number of afri-cola nodes
+# ##count_drink_club-mate## => number of club nodes
+# ##date_drink_afri-cola## => date of afri-cola nodes
+# ##date_drink_club-mate## => date of club nodes
# Open files
infile = File.new($html_infile)
@@ -264,14 +263,14 @@ def parse(infile, outfile, drink_tag, description_extra, icons)
result = $&
case $1
- when "count_drink_club_mate"
- result = $count_drink_club_mate
- when "count_drink_afri_cola"
- result = $count_drink_afri_cola
- when "date_drink_club_mate"
- result = $date_drink_club_mate
- when "date_drink_afri_cola"
- result = $date_drink_afri_cola
+ when "count_drink_club-mate"
+ result = $count["club-mate"]
+ when "count_drink_afri-cola"
+ result = $count["afri-cola"]
+ when "date_drink_club-mate"
+ result = $date["club-mate"]
+ when "date_drink_afri-cola"
+ result = $date["afri-cola"]
end
result.to_s
diff --git a/matekate.html.in b/matekate.html.in
index ed5372b..45ddeb1 100644
--- a/matekate.html.in
+++ b/matekate.html.in
@@ -86,9 +86,9 @@
// Add overlay for drink:club-mate=* tagged locations
var drink_club_mate = new OpenLayers.Layer.Text(
"\
- drink:club-mate=* \
- (##count_drink_club_mate##) \
- ##date_drink_club_mate##\
+ drink:club-mate \
+ (##count_drink_club-mate##) \
+ ##date_drink_club-mate##\
",
{
location:"./drink_club-mate.txt",
@@ -99,9 +99,9 @@
// Add overlay for drink:afri-cola=* tagged locations
var drink_afri_cola = new OpenLayers.Layer.Text(
"\
- drink:afri-cola=* \
- (##count_drink_afri_cola##) \
- ##date_drink_afri_cola##\
+ drink:afri-cola \
+ (##count_drink_afri-cola##) \
+ ##date_drink_afri-cola##\
",
{
location:"./drink_afri-cola.txt",