Http get decoding

thanks for all the help, i (we getting thier), im trining to start picking the data i want and putting into arry/map...? but not sure what im doing

 wkStr.eachLine{
                    if(!it.startsWith(" ")){
                    List dSplit= it.split(":")
                    if(dSplit.size()>1){
                        //log.debug "dsplit= $dSplit"
                      //if (dSplit[0].trim()=="BEGIN" && dSplit[1].trim()=="VEVENT") eCount++    //.startsWith(" ")
                        if (dSplit[0]=="BEGIN" && dSplit[1].trim()=="VEVENT") eCount++    //.startsWith(" ")
                            if (dSplit[0]=="SUMMARY" ){ //|| dSplit[0]=="DTSTART"
                                
                        iCalMap.put(eCount+":"+[dSplit[0].trim()+":"+dSplit[1].trim()].toString())
                            }
                        //log.debug "ical map >1= $iCalMap}"
                    }
                    else {

See if this helps:

	HashMap iCalMap = [:] 
    iCalMap.put("event",[:])
    Integer eCount = 0
    wkStr.eachLine{
        List dSplit= it.split(":")
        
        if(dSplit.size()>1){
            if (dSplit[0].trim()=="BEGIN" && dSplit[1].trim()=="VEVENT") {
                eCount++
                iCalMap.event.put(eCount.toString(),[:])
            }
            if (dSplit[0].trim()=="SUMMARY") 
                iCalMap.event[eCount.toString()].put("summary",dSplit[1].trim())
            else if (dSplit[0].trim().contains("DTSTART"))
                iCalMap.event[eCount.toString()].put("start",dSplit[1].trim())
            else if(dSplit[0].trim().contains("DTEND"))
                iCalMap.event[eCount.toString()].put("end",dSplit[1].trim())
            else if (dSplit[0].trim()=="LOCATION") 
                iCalMap.event[eCount.toString()].put("location",dSplit[1].trim())
    }

getting a null error


Tried to contain but still getting it

wkStr.eachLine{
                    if(!it.startsWith(" ")){
                    List dSplit= it.split(":")
                    if(dSplit.size()>1){
                         if (dSplit[0].trim()=="BEGIN" && dSplit[1].trim()=="VEVENT") {
                            eCount++
                            if (eCount < 0 ) iCalMap.event.put(eCount.toString(),[:])
                        }
                        if (eCount != 0 && dSplit[1].trim()!=null){
                            if (dSplit[0].trim()=="SUMMARY") iCalMap.event[eCount.toString()].put("summary",dSplit[1].trim())
                            else if (dSplit[0].trim().contains("DTSTART")) iCalMap.event[eCount.toString()].put("start",dSplit[1].trim())
                            else if (dSplit[0].trim().contains("DTEND")) iCalMap.event[eCount.toString()].put("end",dSplit[1].trim())
                            else if (dSplit[0].trim()=="LOCATION") iCalMap.event[eCount.toString()].put("location",dSplit[1].trim())
                       }
                    }

Did you catch the additional

iCalMap.put("event",[:])

up at the top?

haddnt but still

edit, commented out the adding to sub map
image

if map blank at start and end must be this thats not working

if (eCount < 0 ) iCalMap.event.put(eCount.toString(),[:])

hmmm, maybe try:

if (eCount < 1) iCalMap.event.put(eCount.toString(),[:])

and put it after you initialize eCount

same
put ti here

if (dSplit[0].trim()=="BEGIN" && dSplit[1].trim()=="VEVENT") {
                            eCount++
                            //if (eCount < 0 ) iCalMap.event.put(eCount.toString(),[:])
                            if (eCount < 1) iCalMap.event.put(eCount.toString(),[:])

eCount at that point should always be > 0 so

if (eCount > 0 ) iCalMap.event.put(eCount.toString(),[:])

or

if (eCount) iCalMap.event.put(eCount.toString(),[:])

or removed the if, put it in earlier as their was a rouge null at the beginning of the file, not sure if this is a map i can do something with now, need to filter out > today and format into an attribute tile

Should be able to process the map using


    for (i=1;i<iCalMap.event.size()+1;i++){
        log.debug iCalMap.event["$i"].start
        wkStr = iCalMap.event["$i"].start
        endStr = wkStr.indexOf("T")
        wkStr = wkStr.substring(0,endStr)
…
    }

at this point and only add the events you’re interested in to the tile attribute by comparing the start of the field to the current date.

dates are my nemesis how do i call a date now() in the format which i can compare against this DTSTART;VALUE=DATE:20150703

trying this

def today = new Date().format( 'yyyyMMdd' )
    Map futEvents = iCalMap.event(id).values().flatten().findAll { it.start > today }

but

add

import java.text.SimpleDateFormat

at the top

and then this should work:


    SimpleDateFormat sdf= new SimpleDateFormat("yyyyMMdd")

    for (i=1;i<iCalMap.event.size()+1;i++){
        wkStr = iCalMap.event["$i"].start
        endStr = wkStr.indexOf("T")
        wkStr = wkStr.substring(0,endStr)
        
        today = sdf.format(new Date()).toString()
        if (today==wkStr) {
            …
        }
      }

This after the try and catch?

That should work. Getting the data in is generally where the issues usually are, once it’s in it should be fairly clean for processing.

just copy as is, it dosnt make much sense to me not shure what its doing and what the new map is going to be called or is it removing from the old map. this is the whole method as is at the mo

void getdata(){
    log.debug "${device} get data"
    //def replace2
    Map reqParams = [
            //uri: "http://${icalink}",
            uri: icalink,
            timeout: 10
        ]
    HashMap iCalMap = [:] 
    try {
        httpGet(reqParams) { resp ->
            if(resp.status == 200) {
                log.debug "rest status${resp.status}"
                wkStr = resp.data
                //log.debug wkStr
	           // HashMap iCalMap = [:]
                   iCalMap.put("event",[:])

                log.debug "iCalMap $iCalMap"
                Integer eCount = 0
                wkStr.eachLine{
                    if(!it.startsWith(" ")){
                    List dSplit= it.split(":")
                    if(dSplit.size()>1){
                         if (dSplit[0].trim()=="BEGIN" && dSplit[1].trim()=="VEVENT") {
                            eCount++
                            iCalMap.event.put(eCount.toString(),[:])
                        }
                        if (eCount != 0 && dSplit[1].trim()!=null){
                            
                            if (dSplit[0].trim().contains("DTSTART")) iCalMap.event[eCount.toString()].put("start",dSplit[1].trim())
                            else if (dSplit[0].trim().contains("DTEND")) iCalMap.event[eCount.toString()].put("end",dSplit[1].trim())
                            else if (dSplit[0].trim()=="LOCATION") iCalMap.event[eCount.toString()].put("location",dSplit[1].trim())
                            else if (dSplit[0].trim()=="STATUS") iCalMap.event[eCount.toString()].put("status",dSplit[1].trim())     //CONFIRMED or TENTATIVE
                            else if (dSplit[0].trim()=="SUMMARY") iCalMap.event[eCount.toString()].put("summary",dSplit[1].trim())
                       }
                    }
                    else {
                       // log.debug "ical map other= $iCalMap}"
                        //iCalMap.put(eCount.toString()+dSplit[0].trim(),dSplit[0].trim(),null)
                        //iCalMap.put(eCount.toString()+dSplit[0].trim(),null)
                        //log.debug "ical map other= $iCalMap}"
                    }
                }
                }
                log.debug "iCalMap  ${iCalMap}"      //.toString()
                //log.debug iCalMap.get("1DESCRIPTION")
            }
            else { // not 200
            
                log.warn "${device} Response code ${resp.status}"
            }
        }
    }
    catch (e) {
        log.warn "${device} CATCH /n $e"
    }

    runIn(state.upFeq,getdata)
}

sorry to be a pain, most stuf i can work out but this...

LOL. I’ve been the one scratching my head more often than not it seems. The part you have in the try..catch loads the map, the for loop allows you to then process data out of the map to create your attribute tile or do other processing with it.

so where do i drop the for loop,
im not putting it back into another 'clean' map then??

Depends on where you’re building your attribute for the tile (the for loop is the selector for your build). The easiest place would be right after the try..catch unless there is some other processing you need to do.

Note that the map is only resident in the method that built it, so if you are doing the processing in another method the map will need to either be stored in an attribute or state and retrieved inside the new method or it will need to be passed as a parameter to the new method.

im looking at hubinfomation driver to look at the html creator, but that looks complicated. mite try hubWD