Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mason-today-web
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
8
Issues
8
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
SRCT
mason-today-web
Commits
f9e4c279
Commit
f9e4c279
authored
Jul 16, 2018
by
Landon DeCoito
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactored appmethods, redisactions. Moved redisdb creation to redisactions
parent
f5408b5b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
34 deletions
+34
-34
mason-today/__init__.py
mason-today/__init__.py
+2
-7
mason-today/appmethods.py
mason-today/appmethods.py
+13
-4
mason-today/redisactions.py
mason-today/redisactions.py
+19
-23
No files found.
mason-today/__init__.py
View file @
f9e4c279
...
...
@@ -4,10 +4,8 @@ from flask import Response
from
flask
import
render_template
# app imports
from
parscript
import
load_data
from
getconnectedscript
import
load_getconn_data
from
redisactions
import
*
from
appmethods
import
*
from
appmethods
import
updatebothdbs
from
redisactions
import
redisdb
# python imports
import
json
...
...
@@ -20,9 +18,6 @@ import time
# setting up flask instance
app
=
Flask
(
__name__
)
# setting up redis database
redisdb
=
redis
.
from_url
(
"redis://localhost:6379/0"
,
db
=
0
)
# setting up cacheing
schedule
.
every
().
day
.
at
(
"02:00"
).
do
(
updatebothdbs
)
# schedule.every(5).seconds.do(updatebothdbs)
...
...
mason-today/appmethods.py
View file @
f9e4c279
...
...
@@ -5,15 +5,24 @@ import redisactions as f
# python imports
import
json
import
datetime
# other imports
import
redis
# attempts to update both dbs and returns true if successful
# attempts to update both dbs and logs the result
def
updatebothdbs
():
livesuccess
=
f
.
livedbfill
(
json
.
dumps
(
load_data
(),
ensure_ascii
=
False
))
gcsuccess
=
f
.
gcdbfill
(
json
.
dumps
(
load_getconn_data
(),
ensure_ascii
=
False
))
print
"DBs updated.
\n
25Live: "
+
str
(
livesuccess
)
\
+
"
\n
GC: "
+
str
(
gcsuccess
)
return
livesuccess
and
gcsuccess
successLog
=
str
(
datetime
.
datetime
.
now
())
\
+
"
\n\n
Attempted to update cache."
\
+
"
\n
25Live: "
+
str
(
livesuccess
)
\
+
"
\n
GC: "
+
str
(
gcsuccess
)
f
.
appendtoupdatelog
(
successLog
)
return
successLog
def
testprint
():
...
...
mason-today/redisactions.py
View file @
f9e4c279
# app imports
from
__init__
import
redisdb
# python imports
import
datetime
...
...
@@ -18,37 +15,36 @@ import redis
# function. and every time we find an error we want to run a dberrorfill()
# function.
# setting up redis database
redisdb
=
redis
.
from_url
(
"redis://localhost:6379/0"
,
db
=
0
)
# this will update the live dictlist and the cachedate
# returns true if the dictlist is not empty, false otherwise
def
gcdbfill
(
dictlist
):
try
:
redisdb
.
set
(
"gcdict"
,
dictlist
)
setlastcachedate
(
"gccachedate"
,
str
(
datetime
.
datetime
.
now
()
))
except
e
:
return
False
success
=
redisdb
.
set
(
"gcdict"
,
dictlist
)
log
=
str
(
datetime
.
datetime
.
now
(
))
redisdb
.
set
(
"gccachedate"
,
log
)
success
=
redisdb
.
get
(
"gccachedate"
)
==
log
and
success
return
redisdb
.
get
(
"gcdict"
)
is
not
None
return
redisdb
.
get
(
"gcdict"
)
is
not
None
and
success
# saves new dictlist in place of previous 25Live dictlist
# returns true if the dictlist is not empty, false otherwise
def
livedbfill
(
dictlist
):
try
:
redisdb
.
set
(
"livedict"
,
dictlist
)
setlastcachedate
(
"livecachedate"
,
str
(
datetime
.
datetime
.
now
()
))
except
e
:
return
False
success
=
redisdb
.
set
(
"livedict"
,
dictlist
)
log
=
str
(
datetime
.
datetime
.
now
(
))
redisdb
.
set
(
"livecachedate"
,
log
)
success
=
redisdb
.
get
(
"livecachedate"
)
==
log
and
success
return
redisdb
.
get
(
"livedict"
)
is
not
None
return
redisdb
.
get
(
"livedict"
)
is
not
None
and
success
# saves the last time the cache was updated
# return true if the cachedate is not empty, false otherwise
def
setlastcachedate
(
cache
,
date
):
try
:
redisdb
.
set
(
cache
,
date
)
except
e
:
return
False
# appends the log string to the head of our update long
# returns true if the head is the newest update
def
appendtoupdatelog
(
logstring
):
redisdb
.
lpush
(
"dbupdatelog"
,
logstring
)
return
redisdb
.
get
(
cache
)
is
not
None
return
redisdb
.
lrange
(
"dbupdatelog"
,
0
,
0
)
==
logstring
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