Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SRCT
mason-today-web
Commits
60e4d24d
Commit
60e4d24d
authored
May 18, 2018
by
Landon DeCoito
Browse files
started database implementation. added redisactions.py to facilitate that
parent
f4c6fb68
Changes
2
Hide whitespace changes
Inline
Side-by-side
mason-today/__init__.py
View file @
60e4d24d
...
...
@@ -10,8 +10,15 @@ from getconnectedscript import load_getconn_data
# python imports
import
json
# other imports
import
redis
from
redisactions
import
*
# setting up flask instance
app
=
Flask
(
__name__
)
# setting up redis database
redisdb
=
redis
.
from_url
(
"redis://localhost:6379/0"
,
db
=
0
)
@
app
.
route
(
"/"
)
def
display_default
():
...
...
@@ -21,15 +28,15 @@ def display_default():
@
app
.
route
(
"/api/25live"
)
def
display_data
():
resp
=
Response
(
json
.
dumps
(
load_data
(),
ensure_ascii
=
False
)
.
encode
(
'utf-8'
))
livedbfill
(
json
.
dumps
(
load_data
(),
ensure_ascii
=
False
)
)
resp
=
Response
(
redisdb
.
get
(
"livedict"
))
#
.encode('utf-8'))
resp
.
headers
[
'Content-Type'
]
=
'application/json; charset=utf-8'
return
resp
@
app
.
route
(
"/api/getconnected"
)
def
display_GC_data
():
resp
=
Response
(
json
.
dumps
(
load_getconn_data
(),
ensure_ascii
=
False
)
.
encode
(
'utf-8'
))
gcdbfill
(
json
.
dumps
(
load_getconn_data
(),
ensure_ascii
=
False
)
)
resp
=
Response
(
redisdb
.
get
(
"gcdict"
))
#
.encode('utf-8'))
resp
.
headers
[
'Content-Type'
]
=
'application/json; charset=utf-8'
return
resp
mason-today/redisactions.py
0 → 100644
View file @
60e4d24d
# third party imports
import
redis
from
__init__
import
redisdb
# I'm thinking we store a couple things
# first: a key-value where the value is the dictlist
# second: a k-v for a list of errored events
# use rpush(key, value) to append a dblist (rpushx() to check if it exists)
# use del(key) to remove a k-v
# so we everytime we run parscript or gcscript we want to run a dbfill()
# function. and every time we find an error we want to run a dberrorfill()
# function.
# this will update the
# returns true if the dictlist is not empty, false otherwise
def
gcdbfill
(
dictlist
):
try
:
redisdb
.
set
(
"gcdict"
,
dictlist
)
except
e
:
return
False
if
redisdb
.
get
(
"gcdict"
)
is
not
None
:
return
True
else
:
return
False
# saves new dictlist in place of previous 25Live dictlist
# returns true if the dictlist is empty, false otherwise
def
livedbfill
(
dictlist
):
try
:
redisdb
.
set
(
"livedict"
,
dictlist
)
except
e
:
return
False
if
redisdb
.
get
(
"livedict"
)
is
not
None
:
return
True
else
:
return
False
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment