Browse Source

First shot at a working adjective service. Depends on falcon and a web whatchamacallit like gunicorn

zed 4 years ago
parent
commit
7194c77365
2 changed files with 1498 additions and 0 deletions
  1. 31 0
      src/AdjectiveService.py
  2. 1467 0
      src/adjectives1.txt

+ 31 - 0
src/AdjectiveService.py

@@ -0,0 +1,31 @@
+import random
+
+import falcon
+
+class Adjectives:
+    def __init__(self):
+        f = open('adjectives1.txt')
+        self.wordlist = f.readlines()
+        random.shuffle(self.wordlist)
+        self.index = 0
+        self.shuffletime = (3 * len(self.wordlist)) / 5
+    def getWord(self):
+        self.index += 1
+        if self.index > self.shuffletime:
+            random.shuffle(self.wordlist)
+            self.index = 0
+        return self.wordlist[self.index]
+
+class AdjectiveGetter:
+    def __init__(self):
+        self.words = Adjectives()
+
+    def on_get(self, req, resp):
+        """Handle GET requests"""
+        resp.status = falcon.HTTP_200
+        resp.body = self.words.getWord()
+
+app = api = falcon.API()
+basicResponder = AdjectiveGetter()
+api.add_route('/basic', basicResponder)
+

File diff suppressed because it is too large
+ 1467 - 0
src/adjectives1.txt