Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
27cda72609
@ -2,6 +2,7 @@ import ujson as json
|
|||||||
import re
|
import re
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
import logging
|
import logging
|
||||||
|
import sys
|
||||||
|
|
||||||
import flask
|
import flask
|
||||||
from flask.ext.login import LoginManager, login_user, login_required, current_user, logout_user, login_fresh, \
|
from flask.ext.login import LoginManager, login_user, login_required, current_user, logout_user, login_fresh, \
|
||||||
@ -14,11 +15,15 @@ from wtforms.validators import DataRequired
|
|||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
logger.setLevel(logging.INFO)
|
logger.setLevel(logging.INFO)
|
||||||
|
console_handler = logging.StreamHandler(sys.stdout)
|
||||||
|
console_handler.setLevel(logging.DEBUG)
|
||||||
handler = logging.FileHandler('wkburned.log')
|
handler = logging.FileHandler('wkburned.log')
|
||||||
handler.setLevel(logging.WARN)
|
handler.setLevel(logging.WARN)
|
||||||
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
||||||
handler.setFormatter(formatter)
|
handler.setFormatter(formatter)
|
||||||
|
console_handler.setFormatter(formatter)
|
||||||
logger.addHandler(handler)
|
logger.addHandler(handler)
|
||||||
|
logger.addHandler(console_handler)
|
||||||
|
|
||||||
app = flask.Flask(__name__)
|
app = flask.Flask(__name__)
|
||||||
logger.debug("Configuring application.")
|
logger.debug("Configuring application.")
|
||||||
@ -118,11 +123,15 @@ class User(db.Model):
|
|||||||
def update_all(self): # pragma: no cover
|
def update_all(self): # pragma: no cover
|
||||||
logger.info("Updating all info for %s", self.api_key)
|
logger.info("Updating all info for %s", self.api_key)
|
||||||
if (datetime.utcnow() - self.last_updated) > timedelta(hours=1):
|
if (datetime.utcnow() - self.last_updated) > timedelta(hours=1):
|
||||||
self.parse_radicals_and_userdata()
|
try:
|
||||||
self.parse_kanji()
|
self.parse_radicals_and_userdata()
|
||||||
self.parse_vocabulary()
|
self.parse_kanji()
|
||||||
self.last_updated = datetime.utcnow()
|
self.parse_vocabulary()
|
||||||
db.session.commit()
|
self.last_updated = datetime.utcnow()
|
||||||
|
db.session.commit()
|
||||||
|
except requests.exceptions.SSLError:
|
||||||
|
logger.error("%s received an SSL error trying to update. Ensure SSL certs are installed.", self.api_key)
|
||||||
|
raise ValueError('Backend SSL Certificate Error, contact administrator.')
|
||||||
else:
|
else:
|
||||||
logger.warn("%s tried to update too frequently", self.api_key)
|
logger.warn("%s tried to update too frequently", self.api_key)
|
||||||
raise ValueError('Cannot refresh now, try again later.')
|
raise ValueError('Cannot refresh now, try again later.')
|
||||||
|
Loading…
Reference in New Issue
Block a user