#! /usr/bin/python import cgi, mc, os, textwrap, random import cgitb; cgitb.enable() def kon() : print 'Connection: close\r\n', print 'Cache-Control: no-cache, must-revalidate\r\n', print 'Expires: Mon, 31 Oct 2005 00:00:00 GMT\r\n', print 'Content-type: text/html;charset=UTF-8\r\n', print '' def gid(lista, ilosc=10) : id = '' l = [] for i in range(ilosc) : while 1 : los = random.randrange(len(lista)) if not los in l : l += [l] break id += str(los) + 'x' return id[:-1] form = cgi.FieldStorage() try : id = form['id'].value.strip() st = int(form['st'].value.strip()) except : kon() print "Error!" kon() #print id #print st tekst = '' gen = '' kat_w = './w/' w = os.listdir(kat_w) w.sort() kat_g = './g/' try : gen = open(kat_g + id + '.txt').read() except : for i in id.split('x') : i = int(i) tekst += open(kat_w + w[i], 'r').read() gen = textwrap.fill(mc.mark_v_shaney(tekst, int(15)), 80) ################################################################################ #random.shuffle(w) gen = '

' + gen + '

' majki = '

' + str(st) for i in range(20) : majki += ' ' + str(i + 1 + st) + ' ' majki += '

' gen += majki ################################################################################ plik = open(kat_g + id + '.txt', 'w') print >> plik, gen plik.close() tytul = '' for c in gen : tytul += c if c == ' ' : if len(tytul) >= 25 : break tytul = tytul.strip() tytul = tytul.replace('

', '') html = open('index.html', 'r').read() html = html[ : html.find('') + len('<title>')] + tytul + html[html.find('') : ] #print html tytul += ' (...)' html = html[ : html.find('') + len('')] + tytul + html[html.find('') : ] html = html[ : html.find('') + len('')] + gen + html[html.find('') : ] print html #print gid(w)