Examples

create a custom local server

The following code creates an instance of a local server. The server expects to find its content in the same folder.

from pyensae import Database

db = Database(dbfile)
df = pandas.DataFrame ( [ {"name":"xavier", "module":"pyrsslocal"} ] )
db.connect()
db.import_dataframe(df, "example")
db.close()

url = "http://localhost:%d/p_aserver.html" % port
webbrowser.open(url)
CustomDBServer.run_server(None, dbfile, port = port, extra_path = os.path.join("."))

The main page is the following one and it can contains a Python script which will be interpreter by the server. It gives access to a variable db which is a local database in SQLlite.

<?xml version="1.0" encoding="utf-8"?>
<html>
<head>
<link type="text/css" href="/p_aserver.css" rel="stylesheet"/>
<title>Custom DB Server</title>
<meta content="dupre, pyrsslocal, custom server" name="keywords"/>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type"/>
<link rel="shortcut icon" href="p_aserver.ico" />
<meta content="CustomServer from pyrsslocal" name="description" />
<script type="text/javascript" src="/p_aserver.js"></script>
<script src="/js/run_prettify.js" type="text/javascript"></script>

</head>

<body onload="setPositions(['divtable', ])" class="mymainbody">

<div class="divtop">
<h1>Custom DB Server unittest</h1>
</div>

<div class="divtable" id="divfiles" onscroll="savePosition('divtable')">

<h2>Content of table example</h2>

<script type="text/python">
print("<table>")
db.connect()
for row in db.execute_view("SELECT * FROM example") :
    srow = [ str(_) for _ in row ]
    print( "<tr><td>{0}</td></tr>".format("</td><td>".join(srow) ) )
db.close()
print("</table>")
</script>

<p>end.</p>

</div>
</body>
</html>

see file aserver.py