Advertisement
Guest User

Untitled

a guest
Mar 5th, 2015
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.45 KB | None | 0 0
  1. "ListOfLa311ServiceRequestNotes": {
  2. "La311ServiceRequestNotes": [
  3. {
  4. "Comment": "Out on the sidewalk near the curb. Hopefully it is still there.",
  5. "CommentType": "Address Comments",
  6. "CreatedByUser": "MYLATHREEONEONE",
  7. "CreatedDate": "02/17/2015 16:53:26",
  8. "Date1": "",
  9. "Date2": "",
  10. "Date3": "",
  11. "FeedbackSRType": "",
  12. "IntegrationId": "021720151654176661",
  13. "IsSrNoAvailable": "",
  14. "ListOfLa311SrNotesAuditTrail": {},
  15. "Notification": "N",
  16. "Text1": ""
  17. },
  18. {
  19. "Comment": "So glad to get rid of this old junk. Thanks.",
  20. "CommentType": "External",
  21. "CreatedByUser": "MYLATHREEONEONE",
  22. "CreatedDate": "02/17/2015 16:53:26",
  23. "Date1": "",
  24. "Date2": "",
  25. "Date3": "",
  26. "FeedbackSRType": "",
  27. "IntegrationId": "021720151654176662",
  28. "IsSrNoAvailable": "",
  29. "ListOfLa311SrNotesAuditTrail": {},
  30. "Notification": "N",
  31. "Text1": ""
  32. }
  33. ]
  34. },
  35.  
  36. ![import json
  37. import jsonpickle
  38. import requests
  39. import arcpy
  40.  
  41. fc = "C:MYLATesting.gdbMYLA311"
  42. if arcpy.Exists(fc):
  43. arcpy.Delete_management(fc)
  44.  
  45. ListTable ="C:MYLATesting.gdbMYLA311Dissolve"
  46. if arcpy.Exists(ListTable):
  47. arcpy.Delete_management(ListTable)
  48.  
  49. f2 = open('C:UsersAdministratorDesktopDetailView.json', 'r')
  50. data2 = jsonpickle.encode( jsonpickle.decode(f2.read()) )
  51.  
  52. url2 = "myURL"
  53. headers2 = {'Content-type': 'text/plain', 'Accept': '/'}
  54.  
  55. r2 = requests.post(url2, data=data2, headers=headers2)
  56. decoded2 = json.loads(r2.text)
  57.  
  58. items = []
  59. for sr in decoded2['Response']['ListOfServiceRequest']['ServiceRequest']:
  60. SRAddress = sr['SRAddress']
  61. latitude = sr['Latitude']
  62. longitude = sr['Longitude']
  63. SRNumber = sr['SRNumber']
  64. FirstName = sr['FirstName']
  65. LastName = sr['LastName']
  66. HomePhone = sr['HomePhone']
  67.  
  68. for ew in sr["ListOfLa311ElectronicWaste"][u"La311ElectronicWaste"]:
  69. CommodityType = ew['Type']
  70. ItemType = ew['ElectronicWestType']
  71. ItemCount = ew['ItemCount']
  72.  
  73. for comm in sr["ListOfLa311ServiceRequestNotes"][u"La311ServiceRequestNotes"]:
  74. Comment = comm['Comment']
  75.  
  76. items.append((SRAddress,
  77. latitude,
  78. longitude,
  79. CommodityType,
  80. ItemType,
  81. SRNumber,
  82. ItemCount,
  83. FirstName,
  84. LastName,
  85. Comment,
  86. HomePhone))
  87.  
  88. import numpy as np #NOTE THIS
  89. dt = np.dtype([('SRAddress', 'U40'),
  90. ('latitude', '<f8'),
  91. ('longitude', '<f8'),
  92. ('Type', 'U40'),
  93. ('ElectronicWestType', 'U40'),
  94. ('SRNumber', 'U40'),
  95. ('ItemCount', 'U40'),
  96. ('FirstName', 'U40'),
  97. ('LastName', 'U40'),
  98. ('Comment', 'U40'),
  99. ('HomePhone', 'U40')])
  100.  
  101. arr = np.array(items,dtype=dt)
  102. sr = arcpy.SpatialReference(4326)
  103. arcpy.da.NumPyArrayToFeatureClass(arr, fc, ['longitude', 'latitude'], sr )
  104.  
  105. arcpy.AddField_management(fc, "SRList", "TEXT", 255)
  106.  
  107. arcpy.AddField_management(fc, "Comments", "TEXT", 255)
  108.  
  109. valueList = [] # empty list
  110. with arcpy.da.SearchCursor(fc,["SRAddress","SRNumber"]) as cursor:
  111. for row in cursor:
  112. # get all combinations of SRAddress & SRNumber
  113. valueList.append(row[0]+str(row[1]))
  114. # make unique value set
  115. valueSet = set(valueList)
  116. # convert set to dictionary keys
  117. valueDict = dict.fromkeys(valueSet)
  118. with arcpy.da.SearchCursor(fc,["SRAddress","SRNumber","ElectronicWestType","ItemCount", "Comment"]) as cursor:
  119. for row in cursor:
  120. # create comma-separated list of values matching each dictionary key
  121. if not valueDict[row[0]+str(row[1])]:
  122. valueDict[row[0]+str(row[1])] = str(row[2]) + ', ' + str(row[3])
  123. else:
  124. valueDict[row[0]+str(row[1])] = str(row[2]) + ', ' + str(row[3]) + ', ' + str(valueDict[row[0]+str(row[1])])
  125. with arcpy.da.UpdateCursor(fc,["SRAddress","SRNumber","SRList"]) as cursor:
  126. for row in cursor:
  127. # write comma-separated list for each row, matching SRAddress & SRNumber
  128. row[2] = valueDict[row[0]+str(row[1])]
  129. cursor.updateRow(row)
  130.  
  131. arcpy.Dissolve_management(fc, "C:MYLATesting.gdbMYLA311Dissolve", ["SRNumber", "SRAddress", "Type", "SRList", "FirstName", "LastName", "HomePhone", "Comment"])
  132.  
  133. print json.dumps(decoded2, sort_keys=True, indent=4)][1]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement