chiark / gitweb /
corrected link to source code
[familyTree.git] / cgiFiles / everyPage.py
1 #!/usr/bin/python
2 # -*- coding:utf-8 -*-
3 import cgi  
4 import cgitb
5 import sys
6 import re
7 sys.path.append('/home/naath/familyTreeProject/familyTree')
8 import askQuestion
9 from random import randrange
10 import codecs
11
12 cgitb.enable()
13 def base_url():
14         return 'http://www.chiark.greenend.org.uk/ucgi/~naath/'
15
16 def make_list(script,text):
17         global pageText
18         if text == 'Random person':
19                 npeople = askQuestion.number_people()
20                 script+='?ID=%d' %(randrange(npeople))
21
22         if script[:4]=='http':
23                 pageText+= '<li><a href=%s>%s</a></li>\n' %(script,text)
24         else:
25                 pageText+= '<li><a href = %s%s>%s</a></li>\n' %(base_url(),script,text)
26
27 def links():
28         global pageText
29         items = []
30         items.append(('searchname.py','Search for people'))
31         items.append(('listPeople.py','List of people'))
32         items.append(('listTerr.py','List of territories'))
33         items.append(('listFam.py','List of families'))
34         items.append(('http://www.chiark.greenend.org.uk/~naath/bigGraph.png',\
35                 'Big Graph'))
36         items.append(('countNames.py','First name'))
37         items.append(('listAge.py','Age at having child'))
38         items.append(('listAgeDeath.py','Age at death'))
39         items.append(('listChildCount.py','Number of children'))
40         items.append(('birthday.py','Birthday calendar'))
41         items.append(('person.py','Random person'))
42         items.append(('aliveOn.py','Alive on date'))
43         items.append((\
44         'http://www.chiark.greenend.org.uk/~naath/spouses-related.html'\
45                 ,'Spouses Related'))
46         items.append((\
47         'http://www.chiark.greenend.org.uk/ucgi/~naath/git/familyTree.git'\
48                 , 'source code'))
49         pageText+= '<hr>\n'
50         for i in range(len(items)):
51                 item = items[i]
52                 if i%4==0 and i!=len(items):
53                         if i!=0:
54                                 pageText+= '</ul>\n'
55                         pageText+= '<ul>\n'
56                 make_list(item[0],item[1])
57         pageText+= '</ul>\n'
58         pageText+= '<hr>\n'
59
60
61
62         
63 def footer():
64         global pageText
65         pageText+= '<hr>\n'
66         pageText+= 'This somewhat silly thing made by \n'
67         pageText+= '<a href=http://www.chiark.greenend.org.uk/~naath>naath</a>\n'
68         pageText+= '<br>\n'
69         pageText+= 'Thanks to <a href=http://www.chiark.greenend.org.uk>chiark</a> for hosting this\n'
70         pageText+= '<br>\n'
71         pageText+= 'Information sourced from <a href = en.wikipedia.org> wikipedia</a>\n'
72         pageText+= 'All errors in transcription are mine.\n'
73         pageText+= 'Reports of errors, or ideas of interesting questions to ask\n'
74         pageText+= 'my database by email to naath@chiark.greenend.org.uk\n'
75         pageText+= "(omissions of people are largely because I haven't got to them yet).\n"
76
77
78
79 def title(titleNum):
80         return 'Silly toy'
81
82 def page_header():
83         global pageText
84         pageText+= 'This is a silly toy for exploring the genealogy of the monarchs of England'
85
86 def top():
87         global pageText
88
89         pageText= "Content-Type: text/html;charset=utf-8\n"
90         pageText+= "\n "
91
92         conn = askQuestion.connect()
93
94         form = cgi.FieldStorage()
95         return [conn,form]
96
97 def html_start(titleNum):
98         global pageText
99         pageText+= "<html>\n"
100         pageText+='<meta charset="UTF-8" />\n'
101         pageText+= "<head>\n"
102         pageText+= "<title>"+ title(titleNum) +"</title>\n"
103
104         pageText+= "<style>\n"
105         pageText+= "ul\n{list-style-type:none;margin:10;padding:0;}\n"
106         pageText+= "li{display:inline;}\n"
107         pageText+= "</style>\n"
108         pageText+= '<script type="text/javascript"'
109         #myScript = '"/home/naath/public-html/sorttable.js"'
110         myScript = 'http://www.chiark.greenend.org.uk/~naath/sorttable.js'
111         pageText+= ' src='+myScript+'></script>'
112
113
114         pageText+= "</head>\n"
115         pageText+= "<body>\n"
116         page_header()
117         links()
118
119 def bad():
120         global pageText
121         html_start(1)
122         pageText+= 'Go Away\n'
123
124 def good(printMe):
125         global pageText
126         html_start(2)
127         pageText+= printMe
128
129 def html_bottom():
130         global pageText
131         links() 
132         footer()
133         pageText+= "</body>\n"
134         pageText+= "</html>\n"
135         askQuestion.close()
136
137 def bottom():
138         global pageText
139         html_bottom()
140
141         print pageText.encode('utf-8')
142 def to_file(file):
143         global pageText
144         html_bottom()
145         pageText = pageText[39:]
146
147         f = codecs.open(file,mode = 'w',encoding = 'utf-8')
148         f.write(pageText)
149         f.close
150
151 global pageText
152 pageText = ''
153