Esempio n. 1
0
  def as_rdf(self):
    http_host = config.default_http_host
    if os.environ.has_key("HTTP_HOST"):
      http_host = os.environ["HTTP_HOST"]
      pass

    url = "http://" + http_host
    date = email.Utils.formatdate(calendar.timegm(email.Utils.parsedate(xhtml.unescape(self["date"]))))
    s = rdf.item(rdf.title(rdf.quote(self["subject"]))
                 + rdf.description(rdf.quote(xhtml.absolutize(self["body"], url)))
                 + "\n"
                 + rdf.link(url)
                 + "\n"
                 + rdf.pubDate(rdf.quote(date)))
    return (s)
Esempio n. 2
0
def generate_rdf(queue):

  http_host = news_config.default_http_host
  if os.environ.has_key("HTTP_HOST"):
    http_host = os.environ["HTTP_HOST"]
    pass

  rdf_file = file_path(queue, "news.rdf")
  
  dirpath = canonical_path(queue)
  names = map(lambda t: dirpath + t, os.listdir(dirpath))
  #names.sort(lambda a, b: cmp(os.stat(a)[stat.ST_MTIME], os.stat(b)[stat.ST_MTIME]))
  names.sort(lambda a, b: cmp(os.stat(a).st_mtime, os.stat(b).st_mtime))
  news_items = map(lambda f: wgo_news.news(f, False), names)
  news_items = filter(lambda n: n.valid, news_items)
             
  news_blotter = file_path(queue, news_config.news_blotter)

  fp = open(rdf_file, "w")
  print >>fp, '<?xml version="1.0" ?>'
  print >>fp, '<?xml-stylesheet href="/style/rdf-news.css" type="text/css" ?>'
  
  print >>fp, rdf.rss.init()
  
  print >>fp, rdf.channel.init()

  print >>fp, rdf.title('GIMP News')
  print >>fp, rdf.link('http://' + http_host)
  print >>fp, rdf.description(rdf.quote('Recent gimp.org ' + queue))
  print >>fp, rdf.pubDate(str(rfc822.formatdate(time.time())))
  #+ string.join(map(lambda n: rdf.item({"resource" : "http://" + http_host}) + "\n", news_items)) + "\n")
  
  map(lambda n: fp.write(str(n.as_rdf())), news_items)

  print >>fp, rdf.channel.fini()
  print >>fp, rdf.rss.fini()
  fp.close()
  
  os.chmod(news_blotter, 0666)

  # this is not the best way to handle this XXX
  if queue == news_config.current_queue:
    os.system("/bin/cp %s %s" % (rdf_file, wgo.config.DocumentRoot_path + "/news.rdf"))
    pass
  
  return (rdf_file)