Python script to get the data from the flex application
I am making a simple Python CGI script that collects data(in xml format) from a flex application and I want to insert it into the mysql database .
In perl The script is looks like the following...
my @samplexml=$cgi->param("Items");
my $data=$xml->XM开发者_开发百科Lin("@samplexml");
foreach my $e(@{$data->{Group}})
{
my $sample="Insert into details(title,Parent,Istreeitem) Values('$e->{title}','$e->{Parent}','$e->{IsTreeItem}')";
my $sam=$dbo->prepare($sample);
$sam->execute();
}
But I want to know how to write these codes in pytrhon script.... Any one can help me?
Thanks in advance. Nimmy.
It should be fairly easy to convert this to a Python script. Setting the stage:
- Python has the cgi module.
- Get the Python-MySQL library (or an equivalent for whatever db you're using).
- Use Python's xml.etree to parse the incoming XML.
You'd write a Python script that'd read the XML from the CGI variables, parse the xml using xml.etree, make a connection to the database, and execute your exact insert statement. The resulting script should look very similar to the above.
If you're not bound to XML, you can consider pyAMF and flex's remoteobjects or other remoting facilities.
精彩评论