-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathapi.py
More file actions
36 lines (26 loc) · 761 Bytes
/
api.py
File metadata and controls
36 lines (26 loc) · 761 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from flask import Flask
import random
from flask_limiter import Limiter
from flask_limiter.util import get_remote_address
from threading import Thread
# Creating the api
app = Flask(__name__)
limiter = Limiter(app, key_func=get_remote_address)
f = open('data.base','r')
quotes = f.read().split(',')
f.close()
"""Opening and reading quotes"""
f = open('sug.base','w')#database to hold suggessions
@app.route('/')#main endpoint to get a quote (no rate limits)
def samuel():
return {"quote":quotes[random.randint(0,len(quotes))]}
@app.route('/submit/<data>')
@limiter.limit("20/minute")
def submit(data):
f.write(f"{data},")
return "200"
def run():
app.run(deubug=True)
def keep_alive():
server = Thread(target=run)
server.start()