Skip to content

Instantly share code, notes, and snippets.

@danielecook
Created February 1, 2018 11:14
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielecook/19793d2faad66d83cef2514c9760f00c to your computer and use it in GitHub Desktop.
Save danielecook/19793d2faad66d83cef2514c9760f00c to your computer and use it in GitHub Desktop.
Generate swot (domain --> school/university)
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