redisactions.py 1.43 KB
Newer Older
1 2 3
# python imports
import datetime

4 5 6 7 8 9 10 11 12 13 14
# 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

15
# so everytime we run parscript or gcscript we want to run a dbfill()
16 17 18
# function. and every time we find an error we want to run a dberrorfill()
# function.

19
# this will update the live dictlist and the cachedate
20 21 22 23
# returns true if the dictlist is not empty, false otherwise
def gcdbfill(dictlist):
    try:
        redisdb.set("gcdict", dictlist)
24
        setlastcachedate("gccachedate", str(datetime.datetime.now()))
25 26 27
    except e:
        return False

28
    return redisdb.get("gcdict") is not None
29 30

# saves new dictlist in place of previous 25Live dictlist
31
# returns true if the dictlist is not empty, false otherwise
32 33 34
def livedbfill(dictlist):
    try:
        redisdb.set("livedict", dictlist)
35
        setlastcachedate("livecachedate", str(datetime.datetime.now()))
36 37 38
    except e:
        return False
        
39 40 41 42 43 44 45 46
    return redisdb.get("livedict") is not None

# 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:
47
        return False
48 49

    return redisdb.get(cache) is not None