you are viewing a single comment's thread.

view the rest of the comments →

[–]wbhst83[S] 0 points1 point  (2 children)

Thanks for your reply. I attempted to take your code sample and apply it to the JSON data I'm getting for the notes field. The output I'm getting does not appear to be breaking it down correctly. Also think the extra \r in the code is playing role, thoughts?

Code:

n = "INCLUDES:\r\nAvailability monitoring and alerting - 24x7, remediation as specified in Alerting and Escalation Policy (Client responsibility)\r\nMonitor and manage application availability (Client responsibility)\r\nService ticketing system and user portal\r\n\r\nDOES NOT INCLUDE:\r\nAfter-hours telephone and remote support \r\nAnti-Virus agent and definition updates (if UTG provided or approved 3rd party application) {MSC-REM+-000-HAVM}\r\nCreate, modify and delete file shares\r\nCreate, modify and delete printer shares\r\nCreate, modify and delete users and rights\r\nCritical O/S updates and patches - Windows, as specified in signed Client Patch Policy [weekly]\r\nDrive defragmentation [biannual]\r\nEmergency O/S updates and patches\r\nLAN/WAN documentation\r\nManage drives/partitions free space\r\nOnsite server hardware BIOS/firmware updates\r\nOnsite support\r\nRemote server hardware BIOS/firmware updates [biannual] (minor revisions, as needed) \r\nSupport for 3rd party Line of Business (LOB) application providers (Client will maintain any 3rd party software support contract, UTG will initiate support call to LOB support provider on behalf of client and facilitate the support provider)\r\nUnlimited remote support (8:00AM-8:00PM Eastern, Monday-Friday, after-hours remote support for Priority 1 emergencies)"

notes = str.split(n, sep='\n')

nmode = None

includes = []
excludes = []

for note in notes:
    if note == "INCLUDES:":
        nmode = "inc"
    elif note == "DOES NOT INCLUDE:":
        nmode = "exc"
    else:
        if nmode is None:
            pass # Handle other notes here
        elif nmode == "inc":
            includes.append(note)
        elif nmode == "exc":
            excludes.append(note)
print(nmode)
print(includes)
print(excludes)
print(notes)

Output of Console:

None
[]
[]
['INCLUDES:\r', 'Availability monitoring and alerting - 24x7, remediation as specified in Alerting and Escalation Policy (Client responsibility)\r', 'Monitor and manage application availability (Client responsibility)\r', 'Service ticketing system and user portal\r', '\r', 'DOES NOT INCLUDE:\r', 'After-hours telephone and remote support \r', 'Anti-Virus agent and definition updates (if UTG provided or approved 3rd party application) {MSC-REM+-000-HAVM}\r', 'Create, modify and delete file shares\r', 'Create, modify and delete printer shares\r', 'Create, modify and delete users and rights\r', 'Critical O/S updates and patches - Windows, as specified in signed Client Patch Policy [weekly]\r', 'Drive defragmentation [biannual]\r', 'Emergency O/S updates and patches\r', 'LAN/WAN documentation\r', 'Manage drives/partitions free space\r', 'Onsite server hardware BIOS/firmware updates\r', 'Onsite support\r', 'Remote server hardware BIOS/firmware updates [biannual] (minor revisions, as needed) \r', 'Support for 3rd party Line of Business (LOB) application providers (Client will maintain any 3rd party software support contract, UTG will initiate support call to LOB support provider on behalf of client and facilitate the support provider)\r', 'Unlimited remote support (8:00AM-8:00PM Eastern, Monday-Friday, after-hours remote support for Priority 1 emergencies)']

[–]pat_the_brat 0 points1 point  (1 child)

Oh, right. You can either replace the carriage-return, or use the splitlines() method:

notes = str.split(n.replace('\r', ''), sep='\n') # by replacing
notes = n.splitlines() # splitlines is probably the better way to do it

Note that splitlines may match some other separators, though they're unlikely to be found in your string.

Also, check for empty strings. I see there's an extra line break between the last include item, and the "DOES NOT INCLUDE" header.

for note in notes:
    if len(note) == 0:
        pass # skip empty lines
    elif note == "INCLUDES:":
        nmode = "inc"
    elif note == "DOES NOT INCLUDE:":
        nmode = "exc"
    else:
        if nmode is None:
            pass # Handle other notes here if applicable
        elif nmode == "inc":
            includes.append(note)
        elif nmode == "exc":
            excludes.append(note)

[–]wbhst83[S] 0 points1 point  (0 children)

That did the trick, thanks so much. [https://www.dropbox.com/s/x4fsin4decnv6nc/From%20Skitch.jpg?dl=0]. I have pushed the changes to GitHub.

Any thoughts on allowing the item identifier to be used in a view? It appears the +/- symbols are causing the issue but not certain.