Created
February 1, 2018 11:14
-
-
Save danielecook/19793d2faad66d83cef2514c9760f00c to your computer and use it in GitHub Desktop.
Generate swot (domain --> school/university)
This file contains hidden or 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 os | |
import shutil | |
import pickle | |
from subprocess import Popen, PIPE | |
from collections import defaultdict | |
out, err = Popen(['git','clone','https://github.com/leereilly/swot'], | |
stdout=PIPE, | |
stderr=PIPE).communicate() | |
school_directory = defaultdict() | |
for root, dirs, files in os.walk("swot/lib/domains"): | |
domain_root = root.split("/")[3:] | |
current_dir = school_directory | |
for i in domain_root: | |
if i not in current_dir.keys(): | |
current_dir[i] = defaultdict() | |
current_dir = current_dir[i] | |
for file in files: | |
domain = file | |
if file != ".DS_Store": | |
with open(root + "/" + file, 'r', encoding="utf-8") as f: | |
school = f.read().strip().encode('utf-8') | |
current_dir[domain] = school.decode('utf-8').split(" In ")[0].strip() | |
shutil.rmtree("swot") | |
with open('school_directory.pkl', 'wb') as f: | |
f.write(pickle.dumps(school_directory)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment