[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: Counter to Fedora 8 release?



Andrew Myers wrote:
Okay this might be a bit harder than I originally thought.  I was
originally thinking of doing something in Javascript but I think
Mairin's suggestion is awesome and I am still happy to have a go at
it.  I might be slow tho...

Okay, here's what I got (see attached files)

run counter.py like so:

python counter.py [input SVG] [number of days to update counter to] [output SVG[

so for example:

python counter.py fedora-countdown-banner.svg 37 fedora-countdown-banner.svg

Anyone want to run with this? hehe, maybe could set this in a cron job, then also write a python script to convert the svg to a png using inkex?

~m

image/svg

import xml.dom.minidom
import sys

def find_node(doc_node, tag_name, attribute_name, attribute_value):
  elements = doc_node.getElementsByTagName(tag_name)
  for element in elements:
    if element.hasAttribute(attribute_name):
      if element.getAttribute(attribute_name) == attribute_value:
        return element

def save_xml_file(doc_node, output_file):
  fp = file(output_file, "w")
  fp.write(doc.toxml())
  fp.close()

def update_counter(doc, counter_node, countdown_value):
  counter_node.replaceChild(doc.createTextNode(countdown_value), counter_node.firstChild)

if __name__ == "__main__":
  print "before buh"
  doc = xml.dom.minidom.parse(sys.argv[1])
  print "buh"
  countdown_value = sys.argv[2]
  output_file = sys.argv[3]

  counter_node = find_node(doc, "tspan", "id", "count-text") 
  update_counter(doc, counter_node, countdown_value)
  
  save_xml_file(doc, output_file)

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]