From 836fa49b0d7561b94d0f5bfb80508ebaeb523f87 Mon Sep 17 00:00:00 2001 From: Nathan Cannon Date: Thu, 24 Dec 2015 00:39:52 +0000 Subject: [PATCH] Switched json parser to improve encoding/decoding times. --- requirements.txt | 19 +++++++------------ wanikaniburned.py | 8 ++++---- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/requirements.txt b/requirements.txt index 79be976..0b6eacf 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,12 +1,7 @@ -Flask==0.10.1 -Flask-Login==0.3.1 -Flask-SQLAlchemy==2.0 -Flask-WTF==0.12 -itsdangerous==0.24 -Jinja2==2.8 -MarkupSafe==0.23 -requests==2.8.0 -SQLAlchemy==1.0.8 -Werkzeug==0.10.4 -wheel==0.24.0 -WTForms==2.0.2 +requests +wtforms +flask +flask-login +flask-sqlalchemy +flask-wtf +ujson \ No newline at end of file diff --git a/wanikaniburned.py b/wanikaniburned.py index a123c8a..24e3bb2 100644 --- a/wanikaniburned.py +++ b/wanikaniburned.py @@ -1,4 +1,4 @@ -import json +import ujson as json import re from datetime import datetime, timedelta @@ -62,7 +62,7 @@ class User(db.Model): self.username = data['user_information']['username'] self.gravatar = data['user_information']['gravatar'] if data.get('requested_information'): - self.radicals = json.dumps(data['requested_information']) + self.radicals = json.dumps(data['requested_information'], ensure_ascii=False) def parse_kanji(self): response = requests.get("https://www.wanikani.com/api/user/" + self.api_key + "/kanji/") @@ -71,7 +71,7 @@ class User(db.Model): if data.get('error'): raise ValueError(data['error']['message']) if data.get('requested_information'): - self.kanji = json.dumps(data['requested_information']) + self.kanji = json.dumps(data['requested_information'], ensure_ascii=False) def parse_vocabulary(self): response = requests.get("https://www.wanikani.com/api/user/" + self.api_key + "/vocabulary/") @@ -80,7 +80,7 @@ class User(db.Model): if data.get('error'): raise ValueError(data['error']['message']) if data.get('requested_information'): - self.vocabulary = json.dumps(data['requested_information']['general']) + self.vocabulary = json.dumps(data['requested_information']['general'], ensure_ascii=False) def update_all(self): if (datetime.utcnow() - self.last_updated) > timedelta(hours=1):