From 79344349561b65ae5e89447cc116ef1a432e216e Mon Sep 17 00:00:00 2001 From: lhess2021 Date: Sat, 21 May 2022 15:43:04 -0400 Subject: [PATCH] add makeDirs() to move csv and html to respective dirs in repo --- .../py-scripts.d/word-count-generator.py | 42 ++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/scripts.d/py-scripts.d/word-count-generator.py b/scripts.d/py-scripts.d/word-count-generator.py index e3f0ec1..c4141e0 100644 --- a/scripts.d/py-scripts.d/word-count-generator.py +++ b/scripts.d/py-scripts.d/word-count-generator.py @@ -1,12 +1,14 @@ import re import os import xml.etree.ElementTree as ET +import glob +import shutil """ This script takes xml canto files and counts the number of unique words as defined by the value of `` nodes. -8 files are generated: csv and html of +8 files are generated: csv and html of cantos - sorted numerically and alphabetically - sorted numerically and alphabetically with blacklist applied """ @@ -28,6 +30,7 @@ def createWordCountDict(cantoFile): wordCountDict[xpathValue(node)] = 1 """ wordCountDict = dict() + print(cantoFile) tree = ET.parse(cantoFile) root = tree.getroot() # TODO @@ -97,6 +100,41 @@ def dictToHtml(sortedDict, sortType, cantoFile): htmlCanto.write(boilerclose) htmlCanto.close() +def makeDirs(): + # moves *.csv to ../comedy-wordcount.d/csv/... + # moves *.html to ../comedy-wordcount.d/html/... + csvFiles = glob.iglob(os.path.join(cantoDir, '*.csv')) + htmlFiles = glob.iglob(os.path.join(cantoDir, '*.html')) + for csvFile in csvFiles: + canticle = csvFile.split('/')[-1].split('-')[1] + if re.search('num\.', csvFile): + numDir = '../../comedy-wordcount.d/csv/' + canticle + '-num/' + shutil.move(csvFile, numDir) + if re.search('num-black', csvFile): + numBlackDir = '../../comedy-wordcount.d/csv/' + canticle + '-num-black/' + shutil.move(csvFile, numBlackDir) + if re.search('alpha\.', csvFile): + alphaDir = '../../comedy-wordcount.d/csv/' + canticle + '-alpha/' + shutil.move(csvFile, alphaDir) + if re.search('alpha-black', csvFile): + alphaBlackDir = '../../comedy-wordcount.d/csv/' + canticle + '-alpha-black/' + shutil.move(csvFile, alphaBlackDir) + for htmlFile in htmlFiles: + canticle = htmlFile.split('/')[-1].split('-')[1] + if re.search('num\.', htmlFile): + numDir = '../../comedy-wordcount.d/html/' + canticle + '-num/' + shutil.move(htmlFile, numDir) + if re.search('num-black', htmlFile): + numBlackDir = '../../comedy-wordcount.d/html/' + canticle + '-num-black/' + shutil.move(htmlFile, numBlackDir) + if re.search('alpha\.', htmlFile): + alphaDir = '../../comedy-wordcount.d/html/' + canticle + '-alpha/' + shutil.move(htmlFile, alphaDir) + if re.search('alpha-black', htmlFile): + alphaBlackDir = '../../comedy-wordcount.d/html/' + canticle + '-alpha-black/' + shutil.move(htmlFile, alphaBlackDir) + + def main(): for canto in os.listdir(cantoDir): if re.search('\.xml$', canto): @@ -120,5 +158,7 @@ def main(): dictToHtml(wordCountDictAlphaSorted, 'alpha', cantoFile) dictToHtml(wordCountDictAlphaSortedBlack, 'alpha-black', cantoFile) + makeDirs() + main()