1 |
commit: 9664464413b7cd59f861eff01148454974e23030 |
2 |
Author: Mart Raudsepp <leio <AT> gentoo <DOT> org> |
3 |
AuthorDate: Sun Dec 4 08:02:10 2016 +0000 |
4 |
Commit: Mart Raudsepp <leio <AT> gentoo <DOT> org> |
5 |
CommitDate: Sun Dec 4 08:02:10 2016 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/grumpy.git/commit/?id=96644644 |
7 |
|
8 |
sync: use requests response.json() directly instead of json.loads |
9 |
|
10 |
This should ensure requests will handle UTF-8 fully correctly for us |
11 |
|
12 |
Suggested-by: Doug Freed <dwfreed <AT> mtu.edu> |
13 |
|
14 |
backend/lib/sync.py | 7 +++---- |
15 |
1 file changed, 3 insertions(+), 4 deletions(-) |
16 |
|
17 |
diff --git a/backend/lib/sync.py b/backend/lib/sync.py |
18 |
index 22419bf..2d6244c 100644 |
19 |
--- a/backend/lib/sync.py |
20 |
+++ b/backend/lib/sync.py |
21 |
@@ -1,5 +1,4 @@ |
22 |
import xml.etree.ElementTree as ET |
23 |
-from flask import json |
24 |
import requests |
25 |
from .. import app, db |
26 |
from .models import Category, Maintainer, Package, PackageVersion |
27 |
@@ -111,7 +110,7 @@ def sync_categories(): |
28 |
url = pkg_url_base + "categories.json" |
29 |
data = http_session.get(url) |
30 |
# TODO: Handle response error (if not data) |
31 |
- categories = json.loads(data.text) |
32 |
+ categories = data.json() |
33 |
existing_categories = {} |
34 |
# TODO: Use UPSERT instead (on_conflict_do_update) if we can rely on postgresql:9.5 |
35 |
for cat in Category.query.all(): |
36 |
@@ -131,7 +130,7 @@ def sync_packages(): |
37 |
if not data: |
38 |
print("No JSON data for category %s" % category.name) # FIXME: Better handling; mark category as inactive/gone? |
39 |
continue |
40 |
- packages = json.loads(data.text)['packages'] |
41 |
+ packages = data.json()['packages'] |
42 |
# TODO: Use UPSERT instead (on_conflict_do_update) |
43 |
existing_packages = {} |
44 |
for pkg in Package.query.all(): |
45 |
@@ -151,5 +150,5 @@ def sync_versions(): |
46 |
print("No JSON data for package %s" % package.full_name) # FIXME: Handle better; e.g mark the package as removed if no pkgmove update |
47 |
continue |
48 |
from pprint import pprint |
49 |
- pprint(json.loads(data.text)) |
50 |
+ pprint(data.json()) |
51 |
break |