I try to launch python script form HTML button. My python script work on text files and reorganize them in folders, so it doesn't have return, it's only an action.
This is my python script
import os
# Compress tabfile
folder_edition = 'D:\\folder_edition'
folder_destination = 'D:\\folder_destination'
for the_file in os.listdir(folder_edition):
if the_file.endswith(".tab"):
fichier_source = folder_edition + "\\" + the_file
fichier_temporaire = folder_compress + "\\" + the_file + "_temp.tab"
fichier_compress = folder_compress + "\\" + the_file.replace("edition_","cclo_")
print fichier_source
result = file(fichier_source,"r").read().replace(" ", " ").replace(" ", " ").replace(" ", " ").replace(" ", " ").replace(" ", " ").strip()
file(folder_compress + "\\" + the_file + "_temporaire.tab","w").write(result)
fichier_in = open(fichier_temporaire,"r")
fichier_out = open(fichier_compress, "w")
for ligne in fichier_in:
if not (ligne.startswith("#") or ligne.startswith(" #") or ligne.startswith(" #") or ligne.startswith(" #") or ligne.startswith(" #") or ligne.startswith(" #")):
fichier_out.write(ligne)
fichier_in.close()
fichier_out.close()
f = file(fichier_compress,"r")
chaine = f.read()
f.close()
result=chaine.replace("\n", " ").replace(" ", " ")
f = file(fichier_compress,"w")
f.write(result)
f.close()
os.remove(fichier_temporaire)
And I tried to call it with a button in HTML
<html>
<div id = "global">
<button class="button_tab" onclick="admin_tab('compress')">Compress</button>
</div>
</html>
And my script where I call my script with Ajax and JQuery
function admin_tab(var_operation)
{
if (var_operation = 'compress') {
$.ajax({
type:'GET',
url: 'script\\python\\compress.py',
timeout: 3000,
async:true,
success: function(response){
alert('Yes !');
},
error: function() {
alert('No !'); }
});
}
};
When I click on the button, HTML correctly read my Python script, but I've any action in folders ...
What can I do for have a similar action, like double click ?