#!/usr/bin/python # Use this to arrange, format, and do whatever else # for the zips of student projects. import os import glob from bs4 import BeautifulSoup basepath = "/Users/zachwhalen/Desktop/dgst395projects/" zips = glob.glob(basepath + "*.zip") for zip in zips: # Figure out the base name name = os.path.basename(zip).split(".")[0] #print(name) # figure out if there's already a folder and if not make one if (os.path.isdir(basepath + name) == False): os.system("mkdir " + basepath + name) # extract the zip file into that folder, forcing overwrites os.system("unzip -oq " + zip + " -d " + basepath + name) zs = glob.glob(basepath + name + "/*") # look for any subfolders and flatten them for z in zs: if (z == basepath + name + '/__MACOSX'): #print("Found __MACOSX: " + z) os.system("rm -rf " + z) if (os.path.isdir(z)): if (z != basepath + name + '/__MACOSX'): os.system("mv " + z + "/* " + basepath + name) os.system("rm -rf " + z) # Now extract the things index = basepath + name + "/index.html" if (os.path.isfile(index)): #print("Found " + index) with open(index, "r") as f: soup = BeautifulSoup(f, 'html.parser') title = soup.h1.text.strip() #what = soup. fields = soup.find_all('td') student_name = fields[0].text.strip() student_name = fields[0].text.strip()[0:-6] print(title + " by " + student_name) else: print("Couldn't find " + index)