able to get data out of database
This commit is contained in:
parent
b7f62bbe97
commit
98f5e361d9
2 changed files with 26 additions and 5 deletions
18
api/db.py
18
api/db.py
|
@ -1,10 +1,20 @@
|
||||||
import redis
|
import redis
|
||||||
|
|
||||||
# connection string and initialization
|
|
||||||
redis_url = 'redis://default:redispw@localhost:32768'
|
redis_url = 'redis://default:redispw@localhost:32768'
|
||||||
r = redis.StrictRedis.from_url(redis_url)
|
r = redis.StrictRedis.from_url(redis_url)
|
||||||
|
|
||||||
#test the connection
|
'''r.set('hello', 'world')
|
||||||
r.set('hello', 'world')
|
|
||||||
value = r.get('hello')
|
value = r.get('hello')
|
||||||
print(value)
|
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
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,22 @@
|
||||||
from typing import *
|
from typing import *
|
||||||
import flask
|
import flask
|
||||||
|
import db
|
||||||
|
|
||||||
class Endpoints:
|
class Endpoints:
|
||||||
|
#db: db.DB
|
||||||
|
|
||||||
def __init__(self, app: flask.Flask):
|
def __init__(self, app: flask.Flask):
|
||||||
app.add_url_rule("/hello", view_func=self.hello, methods=["GET"])
|
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):
|
def hello(self):
|
||||||
return "Hello world!"
|
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))
|
Reference in a new issue