chiark / gitweb /
I'm sure I've done something since I remembered to commit...
[familyTree.git] / familyTree / spousesRelated.py
1 #!/usr/bin/python
2
3 import sys
4 import re
5 sys.path.append('/home/naath/familyTreeProject/cgiFiles')
6 import askQuestion as aQ
7 import graphQuestions as gQ
8 import printUtils as pU
9 import englishUtils as eU
10 import everyPage
11 import cgi
12
13 [conn,form]=everyPage.top()
14
15
16 conn = aQ.connect()
17
18 s = "select * from marriages ORDER BY ida;"
19 printMe=''
20 nPeople = aQ.number_people()
21
22 th = '<th>'
23 eth = '</th>'
24 td = '<td>'
25 etd = '</td>'
26
27
28 #printMe=pU.table_header(['person 1','ID1','person 2','ID2','relationship','year of marriage'],'<br>')
29 printMe=pU.table_header(['person 1','person 2','relationship','year of marriage'],'<br>')
30
31 cuz = re.compile('(<a.*?</a>) and (<a.*?</a>) are (.*)')
32 parent = re.compile('(<a.*?</a>) is (<a.*?</a>)\'s (.*)')
33 for row in aQ.run_query(s,()):
34         if not eU.is_number(row[1]):
35                 continue
36
37         ID1=int(row[0])
38         ID2=int(row[1])
39         if ID2>nPeople or ID1>nPeople or  ID2==0:
40                 continue
41
42         relationship = row[-1]
43         
44         if relationship=='0':
45                 relationship = aQ.find_relationship(ID1,ID2,0)
46         
47         if relationship[-15:]!='are not related':
48                 print relationship
49                 marriedYear = pU.print_year(row[4])
50                 
51
52                 splitR = cuz.search(relationship)
53                 if splitR is None:
54                         splitR = parent.search(relationship)
55 #need to get ID numbers out of the URL because they are sometimes reversed
56 #should be a simple regex               
57 #               cols = [splitR.group(1),ID1,splitR.group(2),\
58 #                       ID2,splitR.group(3),marriedYear]
59                 cols = [splitR.group(1),splitR.group(2),\
60                         splitR.group(3),marriedYear]
61
62                 printMe+=pU.table_row(cols,'<br>')
63                 
64                 
65 printMe+=pU.table_foot('<br>')
66 aQ.commit_changes()
67
68 aQ.close()
69
70 everyPage.good(printMe)
71 file = '/home/naath/public-html/spouses-related.html'
72 everyPage.to_file(file)
73 print 'done'
74
75