redisactions.py 1.43 KB
Newer Older
1 2 3
# app imports
from __init__ import redisdb

4 5 6
# python imports
import datetime

7
# other imports
8 9 10 11 12 13 14 15 16
import redis

# 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

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

21

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

31
    return redisdb.get("gcdict") is not None
32

33

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

43 44
    return redisdb.get("livedict") is not None

45

46 47 48 49 50 51
# 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:
52
        return False
53 54

    return redisdb.get(cache) is not None