Commits

Tobias Berling committed d36ad18

Added max retries for finding new unused key

Comments (0)

Files changed (1)

 from flask import abort, request, make_response
 app = Flask(__name__)
 
-#DATABASE = '/var/www/default/karottika.de/htdocs/paste2/prod.db'
-DATABASE = '/home/tobi/paste2/prod.db'
+DATABASE = '/path/to/sqlite3.db'
 
 def connect_db():
     return sqlite3.connect(DATABASE)
     key = ''
     chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
     i = 0
+    r = 0
     while i < 4:
         n = random.randint(0,35)
         key += chars[n]
         return "i need moar\n"
 
     key = new_key()
+    retries = 10
     while query_db('SELECT key FROM entries WHERE key = ?', [key], one=True):
         key = new_key()
+        retries -= 1
+        if retries == 0:
+            abort(500)
 
     g.db.execute("""
         INSERT INTO entries (key, content, created)