Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.81 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # Usage: update json file
  3. import json
  4. import os
  5.  
  6. json_dir="/opt/rdm/adggeth/ADGG-ETH-02/20181008/"
  7. json_dir_processed="/opt/rdm/adggeth/ADGG-ETH-02/20181008updated/"
  8. for json_file in os.listdir(json_dir):
  9. if json_file.endswith(".json"):
  10. processed_json = "%s%s" % (json_dir_processed, json_file)
  11. json_file = json_dir + json_file
  12. print "Processing %s -> %s" % (json_file, processed_json)
  13. with open(json_file, 'r') as f:
  14. json_data = json.load(f)
  15. if "grp_farmerreg/farmerdetails/farmermobile" not in json_data:
  16. json_data["grp_farmerreg/farmerdetails/farmermobile"] = json_data["grp_farmerdts/hh_id"]
  17. else if "grp_farmerdts/hh_region" not in json_data:
  18. json_data["grp_farmerdts/hh_region"] = json_data["grp_farmerdts/region"]
  19. else if "grp_farmerdts/hh_district" not in json_data:
  20. json_data["grp_farmerdts/hh_district"] = json_data["grp_farmerdts/district"]
  21. else if "grp_farmerdts/hh_ward" not in json_data:
  22. json_data["grp_farmerdts/hh_ward"] = json_data["grp_farmerdts/ward"]
  23. else if "grp_farmerdts/hh_village" not in json_data:
  24. json_data["grp_farmerdts/hh_village"] = json_data["grp_farmerdts/village"]
  25. else
  26. print "No Update to JSON keys"
  27. with open(processed_json, 'w') as f:
  28. f.write(json.dumps(json_data, indent=4))
  29. else:
  30. print "%s not a JSON file" % json_file
  31.  
  32. {
  33. ....
  34. "farmerregistrd": "1",
  35. "grp_farmerdts/region": "5",
  36. "datacollid": "0923678275",
  37. "_status": "submitted_via_web",
  38. "enumtype": "2",
  39. "deviceid": "352948096845916",
  40. "start_time": "2019-04-03T10:57:23.620+03",
  41. "_uuid": "f1069eae-33f8-4850-a549-49fcde27f077",
  42. "grp_farmerdts/village": "2852",
  43. "_submitted_by": null,
  44. "formhub/uuid": "42cb3fc351a74fd89702078160f849ca",
  45. "grp_farmerdts/hh_id": "623",
  46. "grp_farmerdts/ward": "136",
  47. ...
  48. "_userform_id": "adggeth_ADGG-ETH-REG02-20181008",
  49. "_id": 711097,
  50. "grp_farmerdts/district": "31"
  51. }
  52.  
  53. {
  54. ....
  55. "farmerregistrd": "1",
  56. "grp_farmerdts/hh_region": "5",
  57. "datacollid": "0923678275",
  58. "_status": "submitted_via_web",
  59. "enumtype": "2",
  60. "deviceid": "352948096845916",
  61. "start_time": "2019-04-03T10:57:23.620+03",
  62. "_uuid": "f1069eae-33f8-4850-a549-49fcde27f077",
  63. "grp_farmerdts/hh_village": "2852",
  64. "_submitted_by": null,
  65. "formhub/uuid": "42cb3fc351a74fd89702078160f849ca",
  66. "grp_farmerdts/hh_id": "623",
  67. "grp_farmerdts/hh_ward": "136",
  68. ...
  69. "_userform_id": "adggeth_ADGG-ETH-REG02-20181008",
  70. "_id": 711097,
  71. "grp_farmerdts/hh_district": "31"
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement