Signed-off-by: Denis 'GNUtoo' Carikli <[email protected]>
---
 data/wikidata/devices.py | 31 +++++++++++++++++++------------
 1 file changed, 19 insertions(+), 12 deletions(-)

diff --git a/data/wikidata/devices.py b/data/wikidata/devices.py
index 87d2bb8..7c340e1 100755
--- a/data/wikidata/devices.py
+++ b/data/wikidata/devices.py
@@ -37,6 +37,21 @@ def is_a_smartphone_or_tablet_model(page):
             return True
     return False
 
+def get_variant_device_name(variant_page):
+    variant_name = variant_page['labels']['en']
+
+    variant_superclasses = variant_page["claims"]["P279"]
+    # Check if the superclass is an instance of smartphone
+    for variant_superclass in variant_superclasses:
+        variant_superclass_page = variant_superclass.getTarget().get()
+        nr_model_instances = 0
+        if is_a_smartphone_or_tablet_model(variant_superclass_page):
+            nr_model_instances += 1
+            assert (nr_model_instances <= 1), "Multiple smartphone mode 
instances"
+            model_name = variant_superclass_page['labels']['en']
+            return model_name
+    return None
+
 def get_all_compatible_devices(replicant_page):
     # Example: {'6.0 0004': { 'GT-I9300': { 'device_name' : 'Galaxy SIII'}}}
     results = {}
@@ -52,22 +67,14 @@ def get_all_compatible_devices(replicant_page):
             variant_version_id = "Q" + 
str(compatible_variant['datavalue']['value']['numeric-id'])
             variant_page = pywikibot.ItemPage(repo, variant_version_id).get()
             variant_name = variant_page['labels']['en']
+            model_name = get_variant_device_name(variant_page)
 
             if variant_name not in results[replicant_version]:
                 results[replicant_version][variant_name] = {}
 
-            # Try to find the associated device model name
-            variant_superclasses = variant_page["claims"]["P279"]
-            # Check if the superclass is an instance of smartphone
-            for variant_superclass in variant_superclasses:
-                variant_superclass_page = variant_superclass.getTarget().get()
-                nr_model_instances = 0
-                if is_a_smartphone_or_tablet_model(variant_superclass_page):
-                    nr_model_instances += 1
-                    assert (nr_model_instances <= 1), "Multiple smartphone 
mode instances"
-                    model_name = variant_superclass_page['labels']['en']
-                    if model_name not in 
results[replicant_version][variant_name]:
-                        
results[replicant_version][variant_name]['device_name'] = model_name
+            if model_name not in results[replicant_version][variant_name]:
+                results[replicant_version][variant_name]['device_name'] = 
model_name
+
     return results
 
 def print_compatible_devices(data):
-- 
2.25.2

_______________________________________________
Replicant mailing list
[email protected]
https://lists.osuosl.org/mailman/listinfo/replicant

Reply via email to