This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

lua api
#4
(05.08.2023, 08:59)mellotron Wrote: hi please i need your help, i use this lua api code to get json data and save it on csv file but when many user send request i have the lines that get mixed up. please how to fixe it.
Code:
<?
require('apps')
require('socket.url')
action = socket.url.unescape( getvar('action') or 'none' )
storagename = socket.url.unescape( getvar('storagename') or 'none')
format = socket.url.unescape( getvar('format') or 'string' )
storagevalue = socket.url.unescape( getvar('value') or '{}')

-- Modification pour gérer le nom de fichier et le répertoire
filename = socket.url.unescape( getvar('storagename') or 'none')
folder = '/home/ftp/Rapport_SatCl/Jour/'

if action == 'storageset' then
  if storagename ~= 'none' then
    if format == 'json' then
      storagevalue = json.decode(storagevalue)
    end
     -- Création et enregistrement du fichier CSV
    if filename ~= 'none' then
      local ip = ngx.var.remote_addr
      local filepath = folder..storagename..".csv"
      local file = io.open(filepath, "a")
      -- Ajout des entêtes de colonnes
    if file:seek('end') == 0 then
   
        file:write("datetime;agenceName;name;caisse;cheque;gestion_de_compte;autre_service;tres_satisfait;satisfait;un_peu_satifait;pas_satisfait;pas_du_tout_satisfait;pas_du_tout;pas_vraiment;plutot_bien;bien;tres_bien;oui;non;commentaire;telephone\n")

    end
   
    for i, row in ipairs(storagevalue) do
     file:write( row['datetime'] ..";"..row['agenceName']..";"..row['name']..";" .. row['caisse'] .. ";" .. row['cheque'] .. ";" .. row['gestion_de_compte'] .. ";" ..row['autres_services'] .. ";" .. row['tres_satisfait'] .. ";" .. row['satisfait'] .. ";" .. row['un_peu_satifait'] .. ";" .. row['pas_satisfait'] .. ";" .. row['pas_du_tout_satisfait'] .. ";" ..row['pas_du_tout']..";" ..row['pas_vraiment'] .. ";" .. row['plutot_bien'] .. ";" .. row['bien'] .. ";" .. row['tres_bien'] ..";" .. row['oui'] .. ";" .. row['non'] .. ";" .. row['commentaire'] .. ";" .. row['telephone'] .. "\n")
    end
      file:close()
      print('file saved as: ' .. filepath)
    else
      print('no filename specified')
    end
  end


?>
hi is it possible to use more than one storage lis on wiser??
Reply


Messages In This Thread
lua api - by mellotron - 05.08.2023, 08:59
RE: lua api - by admin - 07.08.2023, 08:22
RE: lua api - by mellotron - 13.08.2023, 18:13
RE: lua api - by mellotron - 24.08.2023, 07:18
RE: lua api - by admin - 24.08.2023, 08:13
RE: lua api - by mellotron - 24.08.2023, 09:17

Forum Jump: