Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # Usage: update json file
- import json
- import os
- json_dir="/opt/rdm/adggeth/ADGG-ETH-02/20181008/"
- json_dir_processed="/opt/rdm/adggeth/ADGG-ETH-02/20181008updated/"
- for json_file in os.listdir(json_dir):
- if json_file.endswith(".json"):
- processed_json = "%s%s" % (json_dir_processed, json_file)
- json_file = json_dir + json_file
- print "Processing %s -> %s" % (json_file, processed_json)
- with open(json_file, 'r') as f:
- json_data = json.load(f)
- if "grp_farmerreg/farmerdetails/farmermobile" not in json_data:
- json_data["grp_farmerreg/farmerdetails/farmermobile"] = json_data["grp_farmerdts/hh_id"]
- else if "grp_farmerdts/hh_region" not in json_data:
- json_data["grp_farmerdts/hh_region"] = json_data["grp_farmerdts/region"]
- else if "grp_farmerdts/hh_district" not in json_data:
- json_data["grp_farmerdts/hh_district"] = json_data["grp_farmerdts/district"]
- else if "grp_farmerdts/hh_ward" not in json_data:
- json_data["grp_farmerdts/hh_ward"] = json_data["grp_farmerdts/ward"]
- else if "grp_farmerdts/hh_village" not in json_data:
- json_data["grp_farmerdts/hh_village"] = json_data["grp_farmerdts/village"]
- else
- print "No Update to JSON keys"
- with open(processed_json, 'w') as f:
- f.write(json.dumps(json_data, indent=4))
- else:
- print "%s not a JSON file" % json_file
- {
- ....
- "farmerregistrd": "1",
- "grp_farmerdts/region": "5",
- "datacollid": "0923678275",
- "_status": "submitted_via_web",
- "enumtype": "2",
- "deviceid": "352948096845916",
- "start_time": "2019-04-03T10:57:23.620+03",
- "_uuid": "f1069eae-33f8-4850-a549-49fcde27f077",
- "grp_farmerdts/village": "2852",
- "_submitted_by": null,
- "formhub/uuid": "42cb3fc351a74fd89702078160f849ca",
- "grp_farmerdts/hh_id": "623",
- "grp_farmerdts/ward": "136",
- ...
- "_userform_id": "adggeth_ADGG-ETH-REG02-20181008",
- "_id": 711097,
- "grp_farmerdts/district": "31"
- }
- {
- ....
- "farmerregistrd": "1",
- "grp_farmerdts/hh_region": "5",
- "datacollid": "0923678275",
- "_status": "submitted_via_web",
- "enumtype": "2",
- "deviceid": "352948096845916",
- "start_time": "2019-04-03T10:57:23.620+03",
- "_uuid": "f1069eae-33f8-4850-a549-49fcde27f077",
- "grp_farmerdts/hh_village": "2852",
- "_submitted_by": null,
- "formhub/uuid": "42cb3fc351a74fd89702078160f849ca",
- "grp_farmerdts/hh_id": "623",
- "grp_farmerdts/hh_ward": "136",
- ...
- "_userform_id": "adggeth_ADGG-ETH-REG02-20181008",
- "_id": 711097,
- "grp_farmerdts/hh_district": "31"
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement