mirror of
https://github.com/TitanEmbeds/Titan.git
synced 2024-12-25 06:27:03 +01:00
Moved everything to database
This commit is contained in:
parent
9a698b7279
commit
8329165c72
@ -4,5 +4,4 @@ flask_limiter
|
|||||||
requests_oauthlib
|
requests_oauthlib
|
||||||
mysql-python
|
mysql-python
|
||||||
Flask-SSLify
|
Flask-SSLify
|
||||||
redislite
|
|
||||||
beaker
|
beaker
|
||||||
|
@ -32,4 +32,5 @@ def index():
|
|||||||
|
|
||||||
@app.before_request
|
@app.before_request
|
||||||
def before_request():
|
def before_request():
|
||||||
|
db.create_all()
|
||||||
discord_api.init_discordrest()
|
discord_api.init_discordrest()
|
||||||
|
@ -8,9 +8,13 @@ def set_keyvalproperty(key, value, expiration=None):
|
|||||||
if q.count() == 0:
|
if q.count() == 0:
|
||||||
db.session.add(KeyValueProperties(key=key, value=value, expiration=expiration))
|
db.session.add(KeyValueProperties(key=key, value=value, expiration=expiration))
|
||||||
else:
|
else:
|
||||||
|
if expiration is not None:
|
||||||
|
converted_expr = datetime.fromtimestamp(time.time() + expiration)
|
||||||
|
else:
|
||||||
|
converted_expr = None
|
||||||
firstobj = q.first()
|
firstobj = q.first()
|
||||||
firstobj.value = value
|
firstobj.value = value
|
||||||
firstobj.expiration = expiration
|
firstobj.expiration = converted_expr
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
def get_keyvalproperty(key):
|
def get_keyvalproperty(key):
|
||||||
@ -24,8 +28,6 @@ def getexpir_keyvalproperty(key):
|
|||||||
q = db.session.query(KeyValueProperties).filter(KeyValueProperties.key == key)
|
q = db.session.query(KeyValueProperties).filter(KeyValueProperties.key == key)
|
||||||
now = datetime.now()
|
now = datetime.now()
|
||||||
if q.count() > 0 and (q.first().expiration is not None and q.first().expiration > 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 int(q.first().expiration.strftime('%s'))
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
@ -2,7 +2,6 @@ import requests
|
|||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
import json
|
import json
|
||||||
from functools import partial
|
|
||||||
from titanembeds.utils import cache
|
from titanembeds.utils import cache
|
||||||
from titanembeds.database import db, KeyValueProperties, get_keyvalproperty, set_keyvalproperty, ifexists_keyvalproperty
|
from titanembeds.database import db, KeyValueProperties, get_keyvalproperty, set_keyvalproperty, ifexists_keyvalproperty
|
||||||
from flask import request
|
from flask import request
|
||||||
|
@ -9,9 +9,9 @@ import string
|
|||||||
import hashlib
|
import hashlib
|
||||||
|
|
||||||
cache_opts = {
|
cache_opts = {
|
||||||
'cache.type': 'file',
|
'cache.type': 'ext:database',
|
||||||
'cache.data_dir': 'tmp/cachedata',
|
'cache.lock_dir': 'tmp/cachelock',
|
||||||
'cache.lock_dir': 'tmp/cachelock'
|
'cache.url': config["database-uri"],
|
||||||
}
|
}
|
||||||
cache = CacheManager(**parse_cache_config_options(cache_opts))
|
cache = CacheManager(**parse_cache_config_options(cache_opts))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user