collect.py: fix scan method file content decoding
authorPetr Štetiar <ynezz@true.cz>
Sun, 13 Sep 2020 08:46:20 +0000 (10:46 +0200)
committerPetr Štetiar <ynezz@true.cz>
Sun, 13 Sep 2020 09:23:38 +0000 (11:23 +0200)
Fixes following error:

 File "misc/collect.py", line 54, in merge_profiles
     obj = json.loads(content.decode("utf-8"))
 AttributeError: 'str' object has no attribute 'decode'

Signed-off-by: Petr Štetiar <ynezz@true.cz>
misc/collect.py

index e22d4197a795296a28831b952283c16263f32aaa..60d863c2f9240c15cdc040c1a6a41d67f999949e 100755 (executable)
@@ -50,7 +50,7 @@ def merge_profiles(profiles, download_url):
                 output["models"][title]["code"] = code
 
     for path, content in profiles.items():
-        obj = json.loads(content.decode("utf-8"))
+        obj = json.loads(content)
 
         if obj["metadata_version"] != SUPPORTED_METADATA_VERSION:
             sys.stderr.write(
@@ -114,7 +114,9 @@ def scrape(args):
             array = json.loads(file.read().decode("utf-8"))
             for profile in filter(lambda x: x.endswith("/profiles.json"), array):
                 with urllib.request.urlopen("{}/{}".format(target, profile)) as file:
-                    profiles["{}/{}".format(target, profile)] = file.read()
+                    profiles["{}/{}".format(target, profile)] = file.read().decode(
+                        "utf-8"
+                    )
         return profiles
 
     if not os.path.isfile(config_path):
@@ -257,7 +259,7 @@ def scan(args):
 
         profiles = {}
         for ppath in Path(path).rglob("profiles.json"):
-            with open(ppath, "r") as file:
+            with open(ppath, "r", encoding="utf-8") as file:
                 profiles[ppath] = file.read()
 
         if len(profiles) == 0: