diff options
author | 2016-12-04 10:02:10 +0200 | |
---|---|---|
committer | 2016-12-04 10:02:10 +0200 | |
commit | 9664464413b7cd59f861eff01148454974e23030 (patch) | |
tree | ebe421ecb6ac7e4cd9f4458b1e7c60966238ec35 | |
parent | sync: Fix UTF-8 handling for projects.xml import (diff) | |
download | grumpy-9664464413b7cd59f861eff01148454974e23030.tar.gz grumpy-9664464413b7cd59f861eff01148454974e23030.tar.bz2 grumpy-9664464413b7cd59f861eff01148454974e23030.zip |
sync: use requests response.json() directly instead of json.loads
This should ensure requests will handle UTF-8 fully correctly for us
Suggested-by: Doug Freed <dwfreed@mtu.edu>
-rw-r--r-- | backend/lib/sync.py | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/backend/lib/sync.py b/backend/lib/sync.py index 22419bf..2d6244c 100644 --- a/backend/lib/sync.py +++ b/backend/lib/sync.py @@ -1,5 +1,4 @@ import xml.etree.ElementTree as ET -from flask import json import requests from .. import app, db from .models import Category, Maintainer, Package, PackageVersion @@ -111,7 +110,7 @@ def sync_categories(): url = pkg_url_base + "categories.json" data = http_session.get(url) # TODO: Handle response error (if not data) - categories = json.loads(data.text) + categories = data.json() existing_categories = {} # TODO: Use UPSERT instead (on_conflict_do_update) if we can rely on postgresql:9.5 for cat in Category.query.all(): @@ -131,7 +130,7 @@ def sync_packages(): if not data: print("No JSON data for category %s" % category.name) # FIXME: Better handling; mark category as inactive/gone? continue - packages = json.loads(data.text)['packages'] + packages = data.json()['packages'] # TODO: Use UPSERT instead (on_conflict_do_update) existing_packages = {} for pkg in Package.query.all(): @@ -151,5 +150,5 @@ def sync_versions(): print("No JSON data for package %s" % package.full_name) # FIXME: Handle better; e.g mark the package as removed if no pkgmove update continue from pprint import pprint - pprint(json.loads(data.text)) + pprint(data.json()) break |