borken camp foo
This commit is contained in:
		
							parent
							
								
									ec3b85046e
								
							
						
					
					
						commit
						b4c15fedb6
					
				
					 1 changed files with 58 additions and 0 deletions
				
			
		
							
								
								
									
										58
									
								
								camp/neinomat-workshops
									
										
									
									
									
										Executable file
									
								
							
							
						
						
									
										58
									
								
								camp/neinomat-workshops
									
										
									
									
									
										Executable file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,58 @@
 | 
			
		|||
#!/usr/bin/env ruby
 | 
			
		||||
$:.unshift('../vendor/ruby-mediawiki/lib')
 | 
			
		||||
require 'mediawiki/dotfile'
 | 
			
		||||
@wiki = MediaWiki.dotfile(nil,'camp')
 | 
			
		||||
 | 
			
		||||
def parse_template(title, template)
 | 
			
		||||
  template_re = Regexp.new("\\\{\\\{" + template + "(.*?)\\\}\\\}", Regexp::MULTILINE)
 | 
			
		||||
 | 
			
		||||
  info = []
 | 
			
		||||
 | 
			
		||||
  if (scanned = @wiki.article(title).text.scan(template_re)) != []
 | 
			
		||||
    scanned.each do |m|
 | 
			
		||||
      fields = {}
 | 
			
		||||
      fields_string = m[0]
 | 
			
		||||
 | 
			
		||||
      inlink = 0
 | 
			
		||||
      field = ""
 | 
			
		||||
      fields_string += "|" unless fields_string.match(/\|$/)
 | 
			
		||||
      fields_string.split(//).each do |c|
 | 
			
		||||
        if c == "|" && inlink == 0
 | 
			
		||||
          (key, value) = field.split(/=/)
 | 
			
		||||
          value.chomp! if value
 | 
			
		||||
          fields[key] = value
 | 
			
		||||
          field = ""
 | 
			
		||||
        else
 | 
			
		||||
          inlink += 1 if c == "["
 | 
			
		||||
          inlink -= 1 if c == "]"
 | 
			
		||||
          field += c
 | 
			
		||||
        end
 | 
			
		||||
      end
 | 
			
		||||
      info << fields
 | 
			
		||||
    end
 | 
			
		||||
  else
 | 
			
		||||
    $stderr.print "Template #{template} not found in #{title}!"
 | 
			
		||||
  end
 | 
			
		||||
 
 | 
			
		||||
  info
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
list = ""
 | 
			
		||||
 | 
			
		||||
@wiki.category("Workshop").articles.each do |article|
 | 
			
		||||
  if article != "Template:Workshop"
 | 
			
		||||
    workshops = parse_template(article, "Workshop")
 | 
			
		||||
 | 
			
		||||
    workshops.each do |workshop|
 | 
			
		||||
      list += "* [[#{article}|#{workshop["what"]}]] "
 | 
			
		||||
      list += "Day " + workshop["day"] + "/" + workshop["start"]
 | 
			
		||||
      list += "\n"
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
p list
 | 
			
		||||
a = @wiki.article("List of workshops")
 | 
			
		||||
a.text = list
 | 
			
		||||
a.submit("wiki ex machina")
 | 
			
		||||
 | 
			
		||||
		Reference in a new issue