From a7d947ba4a9d2ece51102b61d6bf11cdb9ec22c7 Mon Sep 17 00:00:00 2001 From: neingeist Date: Fri, 13 Oct 2006 18:08:25 +0000 Subject: [PATCH] Put some stuff into a simple lib --- neinomat-radio-chaotica | 30 +----------------------------- neinomat-termine | 33 +++------------------------------ neinomat.lib.rb | 28 ++++++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 59 deletions(-) create mode 100644 neinomat.lib.rb diff --git a/neinomat-radio-chaotica b/neinomat-radio-chaotica index d552ac3..505d978 100755 --- a/neinomat-radio-chaotica +++ b/neinomat-radio-chaotica @@ -5,6 +5,7 @@ require 'cgi' require 'date' require 'erb' require 'net/http' +require 'neinomat.lib.rb' #---------------------------------------------------------------------------- # Constants @@ -15,35 +16,6 @@ require "#{$0}.templates.rb" #---------------------------------------------------------------------------- # Some helper functions -def parse_template(title, template) - template_re = Regexp.new("\\\{\\\{" + template + "(.*?)\\\}\\\}") - - fields = {} - - fields_string = @wiki.article(title).text.scan(template_re)[0][0] - - inlink = 0 - field = "" - fields_string += "|" unless fields_string.match(/\|$/) - fields_string.split(//).each do |c| - if c == "|" && inlink == 0 - (key, value) = field.split(/=/) - fields[key] = value - field = "" - else - inlink += 1 if c == "[" - inlink -= 1 if c == "]" - field += c - end - end - - fields -end - -def datum2isodate(datum) - return datum[6..9] + "-" + datum[3..4] + "-" + datum[0..1] -end - def head(url) uri = URI.parse(url) diff --git a/neinomat-termine b/neinomat-termine index 2839f4e..01524b0 100755 --- a/neinomat-termine +++ b/neinomat-termine @@ -1,40 +1,13 @@ #!/usr/bin/env ruby $:.unshift('vendor/ruby-mediawiki/lib') require 'mediawiki/dotfile' -@wiki = MediaWiki.dotfile(nil,'entropia') - require 'date' +require 'neinomat.lib.rb' -#---------------------------------------------------------------------------- - -def parse_template(title, template) - template_re = Regexp.new("\\\{\\\{" + template + "(.*?)\\\}\\\}") - - fields = {} - - fields_string = @wiki.article(title).text.scan(template_re)[0][0] - - inlink = 0 - field = "" - fields_string += "|" unless fields_string.match(/\|$/) - fields_string.split(//).each do |c| - if c == "|" && inlink == 0 - (key, value) = field.split(/=/) - fields[key] = value - field = "" - else - inlink += 1 if c == "[" - inlink -= 1 if c == "]" - field += c - end - end +@wiki = MediaWiki.dotfile(nil,'entropia') - fields -end -def datum2isodate(datum) - return datum[6..9] + "-" + datum[3..4] + "-" + datum[0..1] -end +#---------------------------------------------------------------------------- def table_termine (t) body = '{| border=1 cellspacing="0" cellpadding="5" style="border-collapse:collapse;"' diff --git a/neinomat.lib.rb b/neinomat.lib.rb new file mode 100644 index 0000000..fcc6f4a --- /dev/null +++ b/neinomat.lib.rb @@ -0,0 +1,28 @@ +def parse_template(title, template) + template_re = Regexp.new("\\\{\\\{" + template + "(.*?)\\\}\\\}") + + fields = {} + + fields_string = @wiki.article(title).text.scan(template_re)[0][0] + + inlink = 0 + field = "" + fields_string += "|" unless fields_string.match(/\|$/) + fields_string.split(//).each do |c| + if c == "|" && inlink == 0 + (key, value) = field.split(/=/) + fields[key] = value + field = "" + else + inlink += 1 if c == "[" + inlink -= 1 if c == "]" + field += c + end + end + + fields +end + +def datum2isodate(datum) + return datum[6..9] + "-" + datum[3..4] + "-" + datum[0..1] +end