able to get data out of database

This commit is contained in:
varnoisy 2023-02-11 19:00:49 +00:00
parent b7f62bbe97
commit 98f5e361d9
2 changed files with 26 additions and 5 deletions

View file

@ -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)
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

View file

@ -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!"
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))