Last active
January 18, 2017 08:24
-
-
Save rmporsch/667030ff309978457d37d943ab52d8ef to your computer and use it in GitHub Desktop.
transforms emails from Dictionary.com to table formatted entries
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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import re | |
newEntry = False | |
words = [] | |
defs = [] | |
definition = [] | |
with open("dict.email", 'r') as f: | |
for line in f: | |
if re.search(re.escape("\\"), line): | |
words.append(re.sub( | |
(re.escape("\\")+".*"+re.escape("\\")), | |
"", | |
line.strip("\\n"))) | |
newEntry = True | |
elif re.search("[0-9]\. ", line): | |
definition.append(line.strip("\\n")) | |
elif re.search("^noun$", line): | |
definition.append(line) | |
elif re.search("^verb$", line): | |
definition.append(line.strip("\\n")) | |
elif re.search("Quotes", line): | |
newEntry = False | |
defs.append("".join(definition)) | |
definition = [] | |
dat = zip(words, defs) | |
import csv | |
with open("Dictionary_output.txt", 'w') as f: | |
writer = csv.writer(f, delimiter='\t') | |
writer.writerows(dat) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment