neingeist
/
neinomaten
Archived
1
0
Fork 0

Put some stuff into a simple lib

master
neingeist 18 years ago
parent d884808187
commit a7d947ba4a

@ -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)

@ -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;"'

@ -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