Changes

Jump to navigation Jump to search
<tr><td>[[Image:Dbxml-2.png]]</td> <td>[[Image:Dbxml-3.png]]</td></tr>
</table>
 
One can also use sqlite that comes with python to query a <tt>category.db</tt>
made from (for example) <tt>enwikiversity-20090627-category.sql</tt>
that contains titles, so reports are more simpler:
<pre>
##
## Put this in python code above
##
import sqlite3
def querycategory(title):
conn = sqlite3.connect('category.db')
c = conn.cursor()
t = (title,)
c.execute('select cat_title from category where cat_title like "%%%s%%" ;' % t)
res = [row[0] for row in c]
conn.commit()
c.close()
return res
 
 
def simplereports(title):
res = querycategory(title)
j = 0
for r in res:
g = r.replace('_',' ')
print g
title= g.encode('utf8')
filename = 'reps%04d.tex' % j
writeres(title,'','',filename)
j = j+1
return j
 
</pre>
 
Similary, add this to tex code
<texcode>
\startluacode
function listtitles(title)
require("python")
pg = python.globals()
wikiversity = python.import("wikidbxml_queryTxn")
r = wikiversity.querycategory(title)
local j = 0
local res = r[j] or {}
while res do
local d = string.format("\%s\\par",string.gsub(tostring(res),'_',' '))
tex.sprint(tex.ctxcatcodes,d)
j = j+1
res = r[j]
end
end
\stopluacode
 
 
\startluacode
function simplereports(title)
require("python")
pg = python.globals()
wikiversity = python.import("wikidbxml_queryTxn")
r = wikiversity.simplereports(title)
local j = tonumber(r)
for v = 0,j-1 do
local d = string.format("\\input reps\%04d ",v)
tex.sprint(tex.ctxcatcodes,d)
end
print( j )
end
\stopluacode
</texcode>
 
and test it with
 
<texcode>
\starttext
{\bfb Query for 'geometr':}
\ctxlua{listtitles("geometr")}%
\ctxlua{simplereports("geometr")}%
\stoptext
</texcode>
Anonymous user

Navigation menu