Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: e0ada09f8e
Fetching contributors…

Cannot retrieve contributors at this time

88 lines (72 sloc) 2.525 kb
#!/usr/bin/python
# -*- coding: utf-8 -*-
#Standard library
import os.path
import codecs
#Third-party modules
from Cheetah.Template import Template
##Internal modules
class DaysLinkedList:
def __init__(self,all=[]):
self.prev=None
self.next=None
self.date=None
self.data=None
self.fname=None
self.all=all
self.all.append(self)
def nextday(self,date,data):
if self.date is not None :
new=DaysLinkedList(self.all)
new.prev=self
self.next=new
else:
new=self
new.date=date
new.data=data
return new
def iterate(self):
cur=self
while cur is not None:
yield cur
cur = cur.next
class iiWebSiteBuilder:
def __init__(self,pgdaytmpl,pgindextmpl,outdir,calendar):
self.daytmpl=pgdaytmpl
self.indextmpl=pgindextmpl
self.outdir=outdir
self.daysll=DaysLinkedList()
curdayll=self.daysll
for day,data in calendar.iteritems():
curdayll=curdayll.nextday(day,data)
curdayll.fname=curdayll.date.strftime('iilinks-%Y-%m-%d.html')
#fast fix to eliminate duplicate pages
dayflink={}
for l in curdayll.data.link:
if l.code==200:
if not dayflink.has_key(l.url):
dayflink[l.url]=l
curdayll.dayflink=dayflink.values()
##
def renderDaysPages(self):
template=Template(codecs.open(self.daytmpl, encoding="UTF-8").read())
for curday in self.daysll.iterate():
date=curday.date
data=curday.data
template.curday=curday
template.curdate=date
template.daydata=data
#fast fix to eliminate duplicate pages
template.dayflinks=curday.dayflink
##
fname=os.path.join(self.outdir,curday.fname)
of=codecs.open(fname,'w', encoding="UTF-8")
of.write(unicode(str(template), 'UTF-8'))
print fname
def renderIndexPage(self):
template=Template(codecs.open(self.indextmpl, encoding="UTF-8").read())
template.daysll=self.daysll
fname=os.path.join(self.outdir,'index.html')
of=codecs.open(fname,'w', encoding="UTF-8")
of.write(unicode(str(template), 'UTF-8'))
print fname
Jump to Line
Something went wrong with that request. Please try again.