Skip to content

Instantly share code, notes, and snippets.

@jeremymaluf
Created October 16, 2023 18:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeremymaluf/e4461294e2f4e68bd4a5e3bcaf4ac704 to your computer and use it in GitHub Desktop.
Save jeremymaluf/e4461294e2f4e68bd4a5e3bcaf4ac704 to your computer and use it in GitHub Desktop.
Arc JSON cleaner
import json
def data_cleaning(notclean: str, cleaned: str, activity_filter: str) -> str:
with open("{}.json".format(notclean), "r") as file:
raw_data = json.load(file)
cleaned_items = [item for item in raw_data['timelineItems'] if item.get('activityType') == activity_filter]
cleaned_dict = {"timelineItems": cleaned_items}
with open('{}.json'.format(cleaned), "w") as f:
json.dump(cleaned_dict, f, indent=4)
return("{} is saved".format(cleaned))
if __name__ == "__main__":
notclean = input("Enter the name of the file to clean (without the .json extension): ")
cleaned = input("Enter the name for the cleaned file (without the .json extension): ")
activity_filter = input("Enter the activity filter ('train' or 'walking'): ")
result = data_cleaning(notclean, cleaned, activity_filter)
print(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment