#1092 Problem with parsing data

Rafay Ahmed Wed 6 Dec 2023

Hello,

I'm currently experiencing an issue parsing data received from SkySpark using the pyhaystack library. Could you please assist me in figuring out how to convert this data into JSON?

Here's an example of the data:

ver:"3.0"
id,cur,scheduleGrid,tz,nextTime,curStatus,point,dis,curVal,sp,kind,siteRef,schedule,nextVal,mod
@p:tfsSmartBuildings:r:2c0726e2-d189496d "West Hills schedule",M,<<
ver:"3.0"
color,date,dateSpan,dis,end,start,val,weekdays
"#3498db",,,"Occupied",21:00:00,05:00:00,T,"mon,tue,wed,thu,fri"
"#7f8c8d",,,"Unocuppied",00:00:00,00:00:00,F,"sun,mon,tue,wed,thu,fri,sat"
>>,"Los_Angeles",2023-12-06T05:00:00-08:00 Los_Angeles,"ok",M,"West Hills schedule",F,M,"Bool",@p:tfsSmartBuildings:r:2b8fba89-a349178e "West Hills, 22801 Roscoe Blvd",M,T,2023-12-05T05:42:59.486Z

I'm specifically interested in extracting the "schedule" and "siteRef" from this Zinc-formatted data. I've attempted various methods such as using hszinc.parse, but none have been successful.

Thank you for your assistance.

Rafay Ahmed Thu 7 Dec 2023

Currently, I've implemented a temporary solution by custom parsing as follows:

def getScheduleData(zinc_data):

result = []
start_index = zinc_data.find("<<")
end_index = zinc_data.find(">>")
if start_index > -1 and end_index > -1:
    zinc_data = zinc_data[start_index:end_index]
    lines = zinc_data.split("\n", 1)
    zinc_data = lines[1]
    zinc_data = hszinc.parse(zinc_data)
    for row in zinc_data:
        dictObject = dataDictionary()
        for val in row:
            dictObject.add(val, str(row[val]))
        result.append(dictObject)
return result

However, a more robust solution would be appreciated if anyone could provide assistance.

Thank you.

Login or Signup to reply.