Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This function provides separate json files. #416

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions filtering.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import json
import os
import string
import sys


def country_filter(src, scope):
"""
Search the data for a single country

:arg src: source dictionary
:arg scope: source selector
"""

def filter(entry, item):
matching = entry["country"]

if item == matching or item == matching.lower() or item == matching.upper():
return True

else:
return False

return [entry for entry in src if filter(entry, scope)]


def main():
args = []


# Retrieve our selecting countries (seperated by commas)
for arg in sys.argv[1:]:
args.append(arg)

if not args:
print("No arguments provided to filter")
return

# Load the source
try:
with open("./world_universities_and_domains.json") as src_file:
src = json.load(src_file)
except:
print("The JSON file doesn't exist")
return


# Write the filtered result
for arg in args:

with open("./{}_filtered_world_universities_and_domains.json".format(arg), "w") as dest_file:
json.dump(country_filter(src, arg), dest_file)


if __name__ == "__main__":
main()