Permalink
Browse files

Adding example

  • Loading branch information...
1 parent 93287b8 commit 1aad0cb35feeba49cc01def273c20ce3c1aa5d93 @coleifer committed Jun 7, 2012
Showing with 31 additions and 0 deletions.
  1. +2 −0 MANIFEST.in
  2. +29 −0 examples/stocks.py
View
@@ -1,3 +1,5 @@
include LICENSE
include MANIFEST.in
include README.rst
+recursive-include docs *
+recursive-include examples *
View
@@ -0,0 +1,29 @@
+import urllib2
+from redis_completion import RedisEngine
+
+engine = RedisEngine(prefix='stocks')
+
+def load_data():
+ url = 'http://media.charlesleifer.com/downloads/misc/NYSE.txt'
+ contents = urllib2.urlopen(url).read()
+ for row in contents.splitlines()[1:]:
+ ticker, company = row.split('\t')
+ engine.store_json(ticker, company, {'ticker': ticker, 'company': company}) # id, search phrase, data
+
+def search(p, **kwargs):
+ return engine.search_json(p, **kwargs)
+
+if __name__ == '__main__':
+ engine.flush()
+ print 'Loading data (may take a few seconds...)'
+ load_data()
+
+ print 'Search data by typing a partial phrase, like "uni sta"'
+ print 'Type "q" at any time to quit'
+
+ while 1:
+ cmd = raw_input('? ')
+ if cmd == 'q':
+ break
+ else:
+ print search(cmd)

0 comments on commit 1aad0cb

Please sign in to comment.