diff --git a/api/db.py b/api/db.py index 04bf230..e0584cb 100644 --- a/api/db.py +++ b/api/db.py @@ -1,10 +1,20 @@ import redis -# connection string and initialization redis_url = 'redis://default:redispw@localhost:32768' r = redis.StrictRedis.from_url(redis_url) -#test the connection -r.set('hello', 'world') +'''r.set('hello', 'world') value = r.get('hello') -print(value) \ No newline at end of file +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 + diff --git a/api/endpoints.py b/api/endpoints.py index 8cf1267..79f66e2 100644 --- a/api/endpoints.py +++ b/api/endpoints.py @@ -1,11 +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!" \ No newline at end of file + 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)) \ No newline at end of file