-
-
Save jeremymaluf/e4461294e2f4e68bd4a5e3bcaf4ac704 to your computer and use it in GitHub Desktop.
Arc JSON cleaner
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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