Anonymous avatar Anonymous committed 94010da Draft

Initial commit. Working version

Comments (0)

Files changed (6)

+\.pyc$
+\.txt$
+\.sqlite
+\..+~
+from elixir import *
+
+metadata.bind = "sqlite:///words.sqlite"
+metadata.bind.echo = False
+session.autocommit = True
+session.autoflush = True
+
+# setup elixir
+setup_all()
+create_all()
+
+#!/usr/bin/python
+
+import sys
+import word_processor
+import word_session
+
+def help_reaction(args):
+    print "this is a help message"
+
+def processfile_reaction(args):
+    word_processor.process_file(args[0])
+
+def session_reaction(args):
+    word_session.words_session()
+
+def main():
+    reactions = {'help' : help_reaction,
+                 'processfile' : processfile_reaction,
+                 'session' : session_reaction}
+    reactions[sys.argv[1]](sys.argv[2:])
+
+if __name__ == '__main__':
+    main()
+from elixir import *
+import db_connection
+
+
+class Word(Entity):
+    word = Field(Unicode(64), unique=True)
+    rating = Field(Integer())
+
+    def __repr__(self):
+        return self.word
+
+
+# setup elixir
+setup_all()
+create_all()
+

word_processor.py

+##################################################
+# word processor. writes words to db
+##################################################
+from __future__ import with_statement
+from elixir import *
+from word import Word
+from db_connection import *
+import re
+import sys
+import argparse
+
+def process_text(Text):
+    Words = re.findall(r'[a-zA-Z]+', Text)
+    for word in Words:
+        word = word.lower()
+        if not Word.query.filter_by(word = word).all():
+            print "[i] found new word %s" % (word)
+            Word(word = word, rating = 0)
+    session.commit()
+
+def process_file(path):
+    print "[i] processing file %s" % (path)
+    with open(path) as f:
+        process_text(f.read())
+
+def main():
+    # parse params
+    parser = argparse.ArgumentParser(description="")
+    parser.add_argument('--file', dest="filepath", type=str)
+    ParseResult = parser.parse_args(sys.argv[1:])
+    process_file(ParseResult.filepath)
+
+if __name__ == '__main__':
+    main()
+from elixir import *
+from word import Word
+from db_connection import *
+
+def promt_word_reaction():
+    Res = ''
+    while Res not in ['k', 'd', 'p', 'q']:
+        Res = raw_input("[k(know), d(don't know), p(postpone), q(quit)] ->")
+    return Res
+
+def word_session_work(word):
+    print "----------------------------------------"
+    print "Current word is : %s (%d)" % (word.word, word.rating)
+    Key = promt_word_reaction()
+    if Key == 'k':
+        print "marked as known"
+        word.rating -= 100
+    elif Key == 'd':
+        print "marked as don't known"
+        word.rating += 100
+    elif Key == 'p':
+        print "word is postponed"
+        word.rating -= 1000
+    elif Key == 'q':
+        print "bye"
+        exit(0)
+    session.commit()
+
+def words_session():
+    print "===== beginig new word session ====="
+    for word in Word.query.order_by(-Word.rating).all():
+        word_session_work(word)
+    print "===== session ended - all words are processed ====="
+
+
+
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.