def print_age_child_count(row,newLine):
if newLine == '<br>':
- script = "age.py?age="+str(row[0])
+ script = "listAge.py?age="+str(row[0])
link = link_Template.substitute(script = \
script, title = add_quotes(row[0]), text = row[0])
out = str(row[1])+print_people(row[1])
def print_age_death_count(row,newLine):
if newLine =='<br>':
- script = "ageDeath.py?age="+str(row[0])
+ script = "listAgeDeath.py?age="+str(row[0])
link = link_Template.substitute(script = script,\
title = add_quotes(row[0]),text = row[0])
out = str(row[1])+print_people(row[1])
else:
return print_row(row,newLine)
+def print_children_count(row,newLine):
+ out = str(row[0])
+
+ if row[0]==1:
+ out = out + ' person '
+ else:
+ out = out + ' people '
+ out = out +'had '
+
+ if newLine == '<br>':
+ script = "listChildCount.py?nc="+str(row[1])
+ link = link_Template.substitute(script =\
+ script, title = add_quotes(row[1]),text = row[1])
+ else:
+ link = str(row[1])
+
+ out = out + link
+
+ if row[1] == 1:
+ out = out + ' child '
+ else:
+ out = out + ' children '
+
+
+ out = out + newLine
+
+ return out
+
def print_tagged_name(relationship,row,newLine):
if row[0]==None:
out = relationship + " not yet entered: " + row[1]
return out
+
+def count_children(newLine):
+
+ s = "SELECT count(*),nc"\
+ +" FROM ("\
+ +" SELECT count(*) AS nc"\
+ +" FROM parents"\
+ +" GROUP BY parentID"\
+ +" HAVING parentID <>'?'"\
+ +" AND parentID <> '0')"\
+ +" GROUP BY nc;"
+
+ out = ''
+ for row in run_query(s,()):
+ out = out + print_children_count(row,newLine)
+ return out
+
+def parents_with_children(nChildren,newLine):
+ s = "SELECT name,parentID"\
+ + " FROM parents"\
+ + " LEFT JOIN people"\
+ + " ON parentID = people.ID"\
+ + " GROUP BY parentID"\
+ + " HAVING count(*) = ?"\
+ + " AND parentID <> 0"\
+ + " ORDER BY bornYear;"
+
+
+ u = "SELECT count(*)"\
+ +" FROM parents INNER JOIN people"\
+ +" ON parents.ID = people.ID"\
+ +" WHERE parentID = ?"\
+ +" AND (diedyear-bornyear>? OR died='present');"
+
+ out = "People who had " + str(nChildren)
+ if nChildren==1:
+ out = out + " child"
+ else:
+ out = out + " children"
+ out = out + ':' + newLine
+
+
+
+ for row in run_query(s,(nChildren,)):
+ out = out + name_html(row,newLine)
+ for r in run_query(u,(row[1],1)):
+ out += " %d survived infancy" % r[0]
+ for r in run_query(u,(row[1],18)):
+ out = out +" and " +str(r[0])+" survived to adulthood"
+ out = out +newLine
+
+ return out
+
def search_name(name,newLine):
s = "SELECT name, ID"\
+" FROM people"\
out = out + print_age_death_count(row,newLine)
return out
+
def people_died_at_age(age,newLine):
s = "SELECT diedYear-bornYear as age, name,ID"\
+" FROM people"\
t = (ID,)
k = 0
+ spellingsOfKing = ['King','Queen','king','queen']
for row in run_query(s,t):
- a=re.match('.*King',row[0])
- b=re.match('.*Queen',row[0])
- if a!=None or b!=None:
- k=1
+ for s in spellingsOfKing:
+ if re.match('.*'+s,row[0]) != None:
+ k = 1
return k