Merge remote-tracking branch 'origin/api' into pivot
This commit is contained in:
commit
0a66e36c85
3 changed files with 56 additions and 0 deletions
20
api/db.py
Normal file
20
api/db.py
Normal file
|
@ -0,0 +1,20 @@
|
|||
import redis
|
||||
|
||||
redis_url = 'redis://default:redispw@localhost:32768'
|
||||
r = redis.StrictRedis.from_url(redis_url)
|
||||
|
||||
'''r.set('hello', 'world')
|
||||
value = r.get('hello')
|
||||
print(value)'''
|
||||
|
||||
|
||||
class DB:
|
||||
|
||||
def getEntry(self, tiploc):
|
||||
return r.hget("tiploc", tiploc)
|
||||
|
||||
def getHash(self, tiploc):
|
||||
response = r.hgetall("tiploc:"+tiploc)
|
||||
response = {a.decode(): response[a].decode() for a in response}
|
||||
return response
|
||||
|
22
api/endpoints.py
Normal file
22
api/endpoints.py
Normal file
|
@ -0,0 +1,22 @@
|
|||
from typing import *
|
||||
import flask
|
||||
import db
|
||||
|
||||
class Endpoints:
|
||||
#db: db.DB
|
||||
|
||||
def __init__(self, app: flask.Flask):
|
||||
app.add_url_rule("/hello", view_func=self.hello, methods=["GET"])
|
||||
app.add_url_rule("/getHash", view_func=self.getHash, methods=["GET"])
|
||||
|
||||
|
||||
def hello(self):
|
||||
return "Hello world!"
|
||||
|
||||
#test
|
||||
'''def getHash(self):
|
||||
return db.r.hget("tiploc:BHAMNWS", "description")'''
|
||||
|
||||
def getHash(self):
|
||||
tiploc = "BHAMNWS"
|
||||
return flask.jsonify(db.DB.getHash(self, tiploc))
|
14
api/main.py
Normal file
14
api/main.py
Normal file
|
@ -0,0 +1,14 @@
|
|||
import flask
|
||||
from flask import *
|
||||
import endpoints
|
||||
|
||||
def main():
|
||||
app = flask.Flask(__name__)
|
||||
endpoints.Endpoints(app)
|
||||
app.run(port=8080, debug=True, host="127.0.0.1")
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
Reference in a new issue