PDA

View Full Version : Problem with URLDownloadToMemory command



rpalmer68
January 15th, 2008, 07:40 PM
I'm having a problem with my script, it used to work until the 523 upgrade and now it doesn't.

But it's taken me this long to get a chance to look into it!
This is my script;

require "lxp.lom" -- xml parsing setup for xml
local retdata = '<schedule_add>'..
'<status>ADDED</status>'..
'<message></message>'..
'</schedule_add>'
local ws_wsURL = '127.0.0.1:8420'
local ws_type = '0'
local ws_captype = '1'
local ws_rec_name=""
local parsepayload = string.Split(pld1, ' ')
local ws_channel = parsepayload[1]
local ws_date = parsepayload[2]
local ws_time = parsepayload[3]
local ws_duration = parsepayload[4]
table.print (parsepayload)
if parsepayload[5] == nil then
ws_rec_name = 'SMS-'..tostring(math.random(9999))
print('No name supplied set to ' ..ws_rec_name)
else
ws_rec_name = parsepayload[5]
print('ws_rec_name set to '..ws_rec_name)
end
print ('Recording Name',ws_rec_name)
local channels = {
[0] = 'TEN%20Digital',
[2] = 'ABC%20TV%20Sydney',
[3] = 'ABC2',
[7] = '7%20Digital',
[9] = 'NINE%20DIGITAL',
[8] = 'SBS%20DIGITAL%201',
[10] = 'TEN%20Digital',
}
local text_channels = {
[0] = 'TEN Digital',
[2] = 'ABC TV Sydney',
[3] = 'ABC2',
[7] = '7 Digital',
[9] = 'NINE DIGITAL',
[8] = 'SBS DIGITAL 1',
[10] = 'TEN Digital',
}
-- parsedate[1] = day, parsedate[2] = month, parsedate[3] = year
local parsedate = string.Split(ws_date, '/')
parsedate[2] = tostring(tonumber(parsedate[2]) - 1 )
table.print (parsedate)
-- parsetime[1] = hour, parsetime[2] = minute
local parsetime = string.Split(ws_time, ':')
table.print (parsetime)
local ws_channel_name = channels[tonumber(ws_channel)]
local text_channel_name = text_channels[tonumber(ws_channel)]
print ('Channel Name',ws_channel_name)
local ws_url = 'http://'..ws_wsURL..'/servlet/ScheduleDataRes?action=03&day='..parsedate[1]..'&month='..parsedate[2]..'&year='..parsedate[3]..
'&hour='..parsetime[1]..'&min='..parsetime[2]..'&channel='..ws_channel_name..'&duration='..ws_duration..
'&type='..ws_type..'&captype='..ws_captype..'&name='..ws_rec_name..'&status=1'
print ('URL',ws_url)
--URL http://127.0.0.1:8420/servlet/ScheduleDataRes?action=03&day=29&month=8&year=07&hour=22&min=00&channel=7%20Digital&duration=30&type=0&captype=1&name=SMS-8435&status=1
d, err = win.URLDownloadToMemory(ws_url, 0)
--print (d,err)
if d then
local data = lxp.lom.parse (d)
table.print(data)

local status = false
local message = false

for k,v in ipairs(data) do
if type(v) == 'table' then
if v.tag == 'status' then
status = v[1] or ''
elseif v.tag == 'message' then
message = v[1] or ''
end
end
end
--print (status,message)

ws_status = ""
ws_summary=""
if status == 'ADDED' then
ws_status = 'Webscheduler request added successfully'
ws_summary = "Channel: "..text_channel_name.."\nDate: "..ws_date.."\nTime: "..ws_time.."\nDuration: "..ws_duration.."\nName: "..ws_rec_name
elseif status == 'FAILED' then
ws_status = 'Webscheduler request FAILED, '..message or 'Unknown'
end
print ('Webscheduler SMS request:- '..ws_status)
-- Generate SMS message
end

When it runs I get the following in the console log;

{ -- #0
[1] = "7",
[2] = "14/01/2008",
[3] = "22:30",
[4] = "13",
} -- #0
No name supplied set to SMS-7689
Recording Name SMS-7689
{ -- #0
[1] = "14",
[2] = "0",
[3] = "2008",
} -- #0
{ -- #0
[1] = "22",
[2] = "30",
} -- #0
Channel Name 7%20Digital
URL http://127.0.0.1:8420/servlet/ScheduleDataRes?action=03&day=14&month=0&year=2008&hour=22&min=30&channel=7%20Digital&duration=13&type=0&captype=1&name=SMS-7689&status=1
...rogram Files\Promixis\Girder5\luascript\lwinfunc.lua:308: attempt to call field `callback' (a number value)
stack traceback:
...rogram Files\Promixis\Girder5\luascript\lwinfunc.lua:308: in function <...rogram Files\Promixis\Girder5\luascript\lwinfunc.lua:306>
[C]: in function `perform'
...rogram Files\Promixis\Girder5\luascript\lwinfunc.lua:381: in function `URLDownloadToMemory'
[string "RP_Automation.gml:\SMS\Webscheduler (WS)\SM..."]:68: in main chunk


Line 58 is the
d, err = win.URLDownloadToMemory(ws_url, 0)

If I run the URL manually I get this returned;


<schedule_add>
<status>ADDED</status>

<message />

</schedule_add>


Which is what I expect.

Any idea what's changed? The 523 update says "Fixed URLDownloadToMemory", strange mine broke :)

Cheers
Richard

Ron
January 15th, 2008, 07:59 PM
try leaving out the '0'

d, err = win.URLDownloadToMemory(ws_url)

rpalmer68
January 15th, 2008, 11:42 PM
Too easy, that fixed it.

Thanks Ron.