From 8329165c7262ea24ac443cf6a1ae38c48a150b42 Mon Sep 17 00:00:00 2001 From: Jeremy Zhang Date: Mon, 24 Apr 2017 19:57:00 -0700 Subject: [PATCH] Moved everything to database --- requirements.txt | 1 - titanembeds/app.py | 1 + titanembeds/database/keyvalue_properties.py | 8 +++++--- titanembeds/discordrest.py | 1 - titanembeds/utils.py | 6 +++--- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/requirements.txt b/requirements.txt index d00a5a4..6039554 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,5 +4,4 @@ flask_limiter requests_oauthlib mysql-python Flask-SSLify -redislite beaker diff --git a/titanembeds/app.py b/titanembeds/app.py index c26f719..40f5b27 100644 --- a/titanembeds/app.py +++ b/titanembeds/app.py @@ -32,4 +32,5 @@ def index(): @app.before_request def before_request(): + db.create_all() discord_api.init_discordrest() diff --git a/titanembeds/database/keyvalue_properties.py b/titanembeds/database/keyvalue_properties.py index 4bb6eec..beed30a 100644 --- a/titanembeds/database/keyvalue_properties.py +++ b/titanembeds/database/keyvalue_properties.py @@ -8,9 +8,13 @@ def set_keyvalproperty(key, value, expiration=None): if q.count() == 0: db.session.add(KeyValueProperties(key=key, value=value, expiration=expiration)) else: + if expiration is not None: + converted_expr = datetime.fromtimestamp(time.time() + expiration) + else: + converted_expr = None firstobj = q.first() firstobj.value = value - firstobj.expiration = expiration + firstobj.expiration = converted_expr db.session.commit() def get_keyvalproperty(key): @@ -24,8 +28,6 @@ def getexpir_keyvalproperty(key): q = db.session.query(KeyValueProperties).filter(KeyValueProperties.key == key) now = datetime.now() if q.count() > 0 and (q.first().expiration is not None and q.first().expiration > now): - print q.first().expiration - print datetime.now().strftime("%Y-%m-%d %H:%M:%S") return int(q.first().expiration.strftime('%s')) return 0 diff --git a/titanembeds/discordrest.py b/titanembeds/discordrest.py index 9e0b989..35b7159 100644 --- a/titanembeds/discordrest.py +++ b/titanembeds/discordrest.py @@ -2,7 +2,6 @@ import requests import sys import time import json -from functools import partial from titanembeds.utils import cache from titanembeds.database import db, KeyValueProperties, get_keyvalproperty, set_keyvalproperty, ifexists_keyvalproperty from flask import request diff --git a/titanembeds/utils.py b/titanembeds/utils.py index 77a9c17..b6e87cf 100644 --- a/titanembeds/utils.py +++ b/titanembeds/utils.py @@ -9,9 +9,9 @@ import string import hashlib cache_opts = { - 'cache.type': 'file', - 'cache.data_dir': 'tmp/cachedata', - 'cache.lock_dir': 'tmp/cachelock' + 'cache.type': 'ext:database', + 'cache.lock_dir': 'tmp/cachelock', + 'cache.url': config["database-uri"], } cache = CacheManager(**parse_cache_config_options(cache_opts))