forked from carbonplan/research
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix title capitalization on comments.js
fix for carbonplan#285 script: import re import sys _skipWords = {"re:", "the", "of", "on", "and", "to"} def capitalize_word(word : str) -> str: if "-" in word: return capitalize_phrase(word, "-") if word not in _skipWords and word.islower(): return word.title() return word def capitalize_phrase(title : str, delim : str) -> str: return delim.join(map(capitalize_word, title.split(delim))) def capitalize_titles(fileName : str): inFile = open(fileName, "r") outFile = open(fileName+".capitalized", "w") while True: line = inFile.readline() if not line: break match1 = re.search("^ title: ([^,]+)", line) match2 = re.search("^ title:$", line) if(match1): capitalized = capitalize_phrase(match1.group(1), " ") outline = " title: " + capitalized + ",\n" elif (match2): outFile.write(" title:\n") nextline = inFile.readline() capitalized = capitalize_phrase(nextline, " ") outline = capitalized else: outline = line outFile.write(outline) inFile.close() outFile.close() def main(): capitalize_titles(sys.argv[1]) if __name__=="__main__": main()
- Loading branch information
1 parent
3d008ad
commit 59daf95
Showing
1 changed file
with
22 additions
and
22 deletions.
There are no files selected for viewing
This file contains 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