1. Jason Scheirer
  2. match-o-matic

Commits

Jason Scheirer  committed 910e621

Dumb web service

  • Participants
  • Parent commits 945b793
  • Branches default

Comments (0)

Files changed (1)

File webservice.py

View file
  • Ignore whitespace
+import os
+
+import bottle
+
+import worddict
+
+@bottle.route('/')
+def index():
+    bottle.response.content_type = 'text/plain'
+    return ("=== API REFERENCE ===\n" +
+            "\n".join(x['rule'] for x in
+                      bottle.app().routes))
+
+@bottle.route('/is_word/:word')
+def is_word(word):
+    return {'is_word': lookup.is_word(word)}
+
+@bottle.route('/matches/:word')
+def matches(word):
+    return {'words': list(lookup.matches(word))}
+
+@bottle.route('/words_starting_with/:word')
+def words_starting_with(word):
+    return {'words': list(lookup.words_with_prefix(word))}
+
+@bottle.route('/words_containing/:word')
+def words_containing(word):
+    return {'words': list(lookup.matches_for_bag(word))}
+
+lookup = worddict.WordLookup(os.path.join(os.path.dirname(
+                                                os.path.abspath(
+                                                        __file__)),
+                                          'words.txt'))
+
+bottle.run(host='localhost', port=8080, reloader=True)