Skip to content

Commit

Permalink
Changes wrt #11
Browse files Browse the repository at this point in the history
  • Loading branch information
Sreeharsha Mudivarti committed Aug 9, 2013
1 parent 74b90d6 commit 2f33da8
Show file tree
Hide file tree
Showing 905 changed files with 15 additions and 60 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
poems_dropbox/raw
Empty file.
45 changes: 0 additions & 45 deletions poems_dropbox/except.log
Original file line number Diff line number Diff line change
@@ -1,48 +1,3 @@
Error in "raw/Anonymous- anonymous- Solomon Grundy.txt": unsupported operand type(s) for -: 'module' and 'unicode'
Error in "raw/Aiken-Conrad-Music-I-Heard-music-i-heard-with-you.txt": unsupported operand type(s) for -: 'module' and 'unicode'
Error in "raw/Aldington-Richard-stanza-1-from-Lesbia-grow-weary-if-you-will.txt": unsupported operand type(s) for -: 'module' and 'unicode'
Error in "raw/Akins-Zoe-Conquered-o-pale-o-vivid-dear.txt": unsupported operand type(s) for -: 'module' and 'unicode'
Error in "raw/Anonymous- Anonymous- Twinkle, twinkle, little star.txt": unsupported operand type(s) for -: 'module' and 'unicode'
Error in "raw/Ashe- No and Yes- If I could choose my.txt": unsupported operand type(s) for -: 'module' and 'unicode'
Error in "raw/Allingham- William- I heard the dogs howl in the moonlight night.txt": unsupported operand type(s) for -: 'module' and 'unicode'
Error in "raw/Arsenberg-Conrad-Walter-To-Hasekawa-perhaps-it-is-no-matter.txt": unsupported operand type(s) for -: 'module' and 'unicode'
Error in "raw/Akins-Zoe-the-wanderer-the-ships-are-lying-in.txt": unsupported operand type(s) for -: 'module' and 'unicode'
Error in "raw/Akins-Zoe-I-Am-the-Wind-I-Am-the-wind-that.txt": unsupported operand type(s) for -: 'module' and 'unicode'
Error in "raw/Anonymous- anonymous- Solomon Grundy.txt": unsupported operand type(s) for -: 'module' and 'unicode'
Error in "raw/Aiken-Conrad-Music-I-Heard-music-i-heard-with-you.txt": unsupported operand type(s) for -: 'module' and 'unicode'
Error in "raw/Anonymous- anonymous- Solomon Grundy.txt": nothing to repeat
Error in "raw/Aiken-Conrad-Music-I-Heard-music-i-heard-with-you.txt": nothing to repeat
Error in "raw/Aldington-Richard-stanza-1-from-Lesbia-grow-weary-if-you-will.txt": nothing to repeat
Error in "raw/Akins-Zoe-Conquered-o-pale-o-vivid-dear.txt":
Error in "raw/Anonymous- anonymous- Solomon Grundy.txt": unacceptable character #x0001: special characters are not allowed
in "<file>", position 102
Error in "raw/Aiken-Conrad-Music-I-Heard-music-i-heard-with-you.txt": unacceptable character #x0001: special characters are not allowed
in "<file>", position 143
Error in "raw/Anonymous- anonymous- Solomon Grundy.txt": unacceptable character #x0001: special characters are not allowed
in "<file>", position 102
Error in "raw/Aiken-Conrad-Music-I-Heard-music-i-heard-with-you.txt":
Error in "raw/Blake-The-Chimney-Sweep-When-my-mother-died-I.txt": 'NoneType' object has no attribute 'group'
Error in "raw/Browning- Robert- Rats! They fought the dogs.txt.txt": 'NoneType' object has no attribute 'group'
Error in "raw/Dickinson- Emily- I'm wife; I've finished that.txt": while scanning for the next token
found character '\t' that cannot start any token
in "<file>", line 9, column 1
Error in "raw/Dickinson- Emily- The heart asks pleasure first.txt": while scanning for the next token
found character '\t' that cannot start any token
in "<file>", line 9, column 1
Error in "raw/Coleridge- Samuel- there is a thorn.txt": while scanning for the next token
found character '\t' that cannot start any token
in "<file>", line 9, column 1
Error in "raw/Blake-The-Chimney-Sweep-When-my-mother-died-I.txt": 'NoneType' object has no attribute 'group'
Error in "raw/Browning- Robert- Rats! They fought the dogs.txt.txt": 'NoneType' object has no attribute 'group'
Error in "raw/Dickinson- Emily- I'm wife; I've finished that.txt": while scanning for the next token
found character '\t' that cannot start any token
in "<file>", line 9, column 1
Error in "raw/Dickinson- Emily- The heart asks pleasure first.txt": while scanning for the next token
found character '\t' that cannot start any token
in "<file>", line 9, column 1
Error in "raw/Coleridge- Samuel- there is a thorn.txt": while scanning for the next token
found character '\t' that cannot start any token
in "<file>", line 9, column 1
Error in "raw/Blake-The-Chimney-Sweep-When-my-mother-died-I.txt": 'NoneType' object has no attribute 'group'
Error in "raw/Browning- Robert- Rats! They fought the dogs.txt.txt": 'NoneType' object has no attribute 'group'
Error in "raw/Dickinson- Emily- I'm wife; I've finished that.txt": while scanning for the next token
Expand Down
29 changes: 14 additions & 15 deletions poems_dropbox/dump_poems.py → poems_dropbox/process_poems.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
#!/usr/bin/env python
"""
Problems
yaml
Usage:
./process_poems.py <dropbox folder>
YAML Problems:
-> -<space>
-> \t
-> \t\n
-> \s*---(.+?)---\s*\n
Poem
Poem Problems:
-> title
-> \t
-> \t\n
"""
import yaml
import random
import re
import StringIO
from glob import glob
Expand All @@ -19,10 +22,6 @@
from pipes import quote
from codecs import open

def random_with_N_digits(n):
range_start = 10**(n-1)
range_end = (10**n)-1
return random.randint(range_start, range_end)

def yaml_and_poem(poem_text):
match = re.search(u"\s*---(.+?)---[ ]*\n", poem_text, flags=re.U | re.S)
Expand Down Expand Up @@ -51,13 +50,13 @@ def clean_name(txtfile):
new_txtfile_name = re.sub(r'[\'",]', "-", new_txtfile_name)
new_txtfile_name = re.sub(" ", "-", new_txtfile_name)
new_txtfile_name = re.sub("-+", "-", new_txtfile_name)
new_txtfile_name = str(random_with_N_digits(6)) + "-" + new_txtfile_name
return new_txtfile_name

os.system("rm -rf raw")
os.system("cp -R \'" + sys.argv[1] + "\' raw")
os.system("cp -R " + quote(sys.argv[1]) + " raw")

log = open("except.log","a")
os.system("rm except.log")
log = open("except.log", "a")

for txtfile in glob("raw/*"):
print txtfile
Expand All @@ -68,12 +67,12 @@ def clean_name(txtfile):
yaml.load(StringIO.StringIO(yaml_cleaned))
cleaned_poem = clean_poem(poem)
final_filename = clean_name(txtfile)
ffh = open("done/" + final_filename,"w", "utf-8")
ffh = open("processed/" + final_filename,"w", "utf-8")
ffh.write(u"---" + yaml_cleaned + u"---\n" + cleaned_poem)
ffh.close()
except Exception, error:
log.write("Error in \"" + txtfile + "\": " + str(error) + "\n")
cmd = "mv " + quote(txtfile) + " except/"
cmd = "mv " + quote(txtfile) + " errors/"
print cmd
os.system(cmd)
continue
Expand Down
Loading

0 comments on commit 2f33da8

Please sign in to comment.