Logic Machine Forum
Vistapool Integration - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Vistapool Integration (/showthread.php?tid=2831)



Vistapool Integration - joost001 - 07.09.2020

Hi all,
 
I’m trying to get some vistapool information integrated in my logicmachine. The information is available in json format after a successful login is accomplished on the site. I have tried the following script but can’t get the parameters overview file. Any help/suggestions?
 
http = require('socket.http')
ltn12 = require('ltn12')
json = require('json')
 
user = 'joost@xxxxxx.xxx'
pass = 'xxxxxx'
remember_password = '0'
entrar = 'Enter'
poolid = 'xxxx'
 
resp = {}
url1 = 'http://www.vistapool.es/en/login/login'
url2 = 'http://www.vistapool.es/en/pool/getmainvalues?id=xxxx'
data = [[{
"user": "joost@xxxxxx.xxxx",
"pass": "xxxx",
"remember_password": "0",
"entrar": "Enter"
}]]
 
 
res, err, hdrs = http.request(url1, data)
log(res, err, hdrs)
 
if res then
  tbl = {}
  res, err = http.request({
    url = url2,
    headers = {
      cookie = hdrs['set-cookie']
    },
    sink = ltn12.sink.table(tbl),
  })
 
  if res then
    resp = table.concat(tbl)
    log(resp)
  else
    alert('request 2 failed: ' .. tostring(err))
  end
else
  alert('request 1 failed: ' .. tostring(err))
end
 
I get the following in the log (no error log, no alert info neither)
string: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="es_ES" lang="es_ES">
 
 
<!--[if lt IE 9]>
    <link rel="stylesheet" type="text/css" href="sfiles/css/IE.css">
    <script src="http://css3-mediaqueries-js.googlecode.com/svn/trunk/css3-mediaqueries.js"></script>
    <![endif]-->
 
    <head>
 
        <title>DA-GEN | DA-GEN | Accede a tu cuenta</title>
        <meta http-equiv="charset" content="utf-8" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Language" content="es_ES" />
<meta http-equiv="X-UA-Compatible" content="IE=edge env=best-standards-support" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=yes" />
<meta name="robots" content="index,follow" />
        <link href="/sfiles/css/footable.core.css" media="screen" rel="stylesheet" type="text/css" />
<link href="/sfiles/css/footable.standalone.css" media="screen" rel="stylesheet" type="text/css" />
<link href="/sfiles/css/bootstrap-select.min.css" media="screen" rel="stylesheet" type="text/css" />
<link href="/sfiles/css/bootstrap-formhelpers.min.css" media="screen" rel="stylesheet" type="text/css" />
<link href="/sfiles/plugins/chosen/chosen.min.css" media="screen" rel="stylesheet" type="text/css" />
<link href="/sfiles/css/bootstrap-clockpicker.min.css" media="screen" rel="stylesheet" type="text/css" />
<link href="/sfiles/css/bootstrap-datetimepicker-ok.css" media="screen" rel="stylesheet" type="text/css" />
<link href="/sfiles/css/bootstrap.css" media="screen" rel="stylesheet" type="text/css" />
<link href="/sfiles/plugins/daterangepicker/daterangepicker-bs3.css" media="screen" rel="stylesheet" type="text/css" />
<link href="/sfiles/css/template.css" media="screen" rel="stylesheet" type="text/css" />
<link href="/sfiles/css/custom.css" media="screen" rel="stylesheet" type="..


Thank you for any help/suggestions,
regards,
Joost


RE: Vistapool Integration - admin - 07.09.2020

Can you send me login/password via PM?


RE: Vistapool Integration - joost001 - 07.09.2020

(07.09.2020, 07:00)admin Wrote: Can you send me login/password via PM?

Just sent via PM. 
regards,
Joost


RE: Vistapool Integration - admin - 07.09.2020

Login part in your example was incorrect. POST data must be encoded correctly.
Code:
user = 'user@example.com'
pass = 'password'
poolid = '123456'

http = require('socket.http')
ltn12 = require('ltn12')
json = require('json')

resp = {}

url1 = 'http://www.vistapool.es/en/login/login'
url2 = 'http://www.vistapool.es/en/pool/getmainvalues?id=' .. poolid

function encodepost(t)
  local res = {}
  local esc = require('socket.url').escape

  for k, v in pairs(t) do
    res[ #res + 1 ] = esc(k) .. '=' .. esc(v)
  end

  return table.concat(res, '&')
end

data = encodepost({
  user = user,
  pass = pass,
  remember_password = '0',
  entrar = 'Enter'
})

res, err, hdrs = http.request(url1, data)
log(res, err, hdrs)

if res then
  tbl = {}
  res, err = http.request({
    url = url2,
    headers = {
      cookie = hdrs['set-cookie']
    },
    sink = ltn12.sink.table(tbl),
  })

  if res then
    resp = table.concat(tbl)
    data = json.pdecode(resp)
    log(data)
  else
    alert('request 2 failed: ' .. tostring(err))
  end
else
  alert('request 1 failed: ' .. tostring(err))
end



RE: Vistapool Integration - joost001 - 09.09.2020

Works like a charm !! thank you very much for the help !

regards,
Joost