fetchphones working with loop
This commit is contained in:
parent
e81d005f58
commit
c9fe1637e8
4 changed files with 75 additions and 47 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,3 +1,4 @@
|
||||||
|
todo.md
|
||||||
db.sqlite3
|
db.sqlite3
|
||||||
|
|
||||||
# ---> Python
|
# ---> Python
|
||||||
|
|
|
@ -139,4 +139,4 @@ REST_FRAMEWORK = {
|
||||||
'DEFAULT_FILTER_BACKENDS': ['django_filters.rest_framework.DjangoFilterBackend']
|
'DEFAULT_FILTER_BACKENDS': ['django_filters.rest_framework.DjangoFilterBackend']
|
||||||
}
|
}
|
||||||
|
|
||||||
LINEAGEWIKI = '/home/francesco/Code/lineage_wiki'
|
LINEAGEWIKI = '/home/d0c/Code/lineage_wiki'
|
||||||
|
|
|
@ -8,11 +8,29 @@ from suitablephones.models import Bluetooth, Camera, Device
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
def set_camera(args):
|
||||||
|
cam = Camera.objects.filter(**args)
|
||||||
|
if not cam.exists():
|
||||||
|
cam = Camera()
|
||||||
|
for subkey, subvalue in args.items():
|
||||||
|
if subkey == 'info':
|
||||||
|
mp = subvalue.split(' ')[0]
|
||||||
|
setattr(cam, 'megapixel', mp)
|
||||||
|
info = ' '.join(map(str, subvalue.split(' ')[2:]))
|
||||||
|
setattr(cam, subkey, info)
|
||||||
|
setattr(cam, subkey, subvalue)
|
||||||
|
cam.save()
|
||||||
|
else:
|
||||||
|
cam = cam.get()
|
||||||
|
return cam
|
||||||
|
|
||||||
|
|
||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
help = 'Aiuto'
|
help = 'Aiuto'
|
||||||
|
|
||||||
#def add_arguments(self, parser):
|
#def add_arguments(self, parser):
|
||||||
# parser.add_argument('poll_ids', nargs='+', type=int)
|
# parser.add_argument('poll_ids', nargs='+', type=int
|
||||||
|
|
||||||
|
|
||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
Device.objects.all().delete()
|
Device.objects.all().delete()
|
||||||
|
@ -20,44 +38,52 @@ class Command(BaseCommand):
|
||||||
Camera.objects.all().delete()
|
Camera.objects.all().delete()
|
||||||
devicesdir = settings.LINEAGEWIKI + "/_data/devices/"
|
devicesdir = settings.LINEAGEWIKI + "/_data/devices/"
|
||||||
for filename in os.listdir(devicesdir):
|
for filename in os.listdir(devicesdir):
|
||||||
|
|
||||||
with open(os.path.join(devicesdir, filename), "r") as stream:
|
with open(os.path.join(devicesdir, filename), "r") as stream:
|
||||||
try:
|
try:
|
||||||
data = yaml.safe_load(stream)
|
data = yaml.safe_load(stream)
|
||||||
|
print(data['codename'])
|
||||||
dev = Device()
|
dev = Device()
|
||||||
for key, value in data.items():
|
for key, value in data.items():
|
||||||
if key == "architecture":
|
# if key == "architecture":
|
||||||
if type(value) == dict():
|
# if type(value) == dict():
|
||||||
setattr(dev, key, value)
|
# setattr(dev, key, value)
|
||||||
else: #type(value) == str():
|
# else: #type(value) == str():
|
||||||
setattr(dev, key, dict({ 'cpu' : value }))
|
# setattr(dev, key, dict({ 'cpu' : value }))
|
||||||
#match caso:
|
#match caso:
|
||||||
# case dict():
|
# case dict():
|
||||||
# print('dict')
|
# print('dict')
|
||||||
elif key == "bluetooth":
|
if key == "bluetooth":
|
||||||
|
if not 'profiles' in value.keys():
|
||||||
|
value['profiles'] = None
|
||||||
# get() returned more than one Bluetooth -- it returned 2!
|
# get() returned more than one Bluetooth -- it returned 2!
|
||||||
bt = Bluetooth.objects.filter(**value)
|
bt = Bluetooth.objects.filter(**value)
|
||||||
# __exact? https://docs.djangoproject.com/en/4.1/ref/models/querysets/#exact
|
# __exact? https://docs.djangoproject.com/en/4.1/ref/models/querysets/#exact
|
||||||
if not bt.exists():
|
if not bt.exists():
|
||||||
bt = Bluetooth()
|
bt = Bluetooth()
|
||||||
for subkey, subvalue in value.items():
|
for subkey, subvalue in value.items():
|
||||||
|
if not hasattr(value, 'profiles'):
|
||||||
|
setattr(bt, 'profiles', None)
|
||||||
setattr(bt, subkey, subvalue)
|
setattr(bt, subkey, subvalue)
|
||||||
bt.save()
|
bt.save()
|
||||||
else:
|
else:
|
||||||
bt = bt.get()
|
bt = bt.get(spec=value['spec'], profiles=value['profiles'])
|
||||||
dev.bluetooth = bt
|
dev.bluetooth = bt
|
||||||
|
dev.save()
|
||||||
elif key == "cameras":
|
elif key == "cameras":
|
||||||
print('camera')
|
dev.save()
|
||||||
# cam = []
|
for c in value:
|
||||||
# for c in Camera.objects.filter(*value.items())
|
cam = set_camera(c)
|
||||||
# cam.append(c)
|
dev.cameras.add(cam)
|
||||||
# if not cam.exists():
|
elif key == "peripherals":
|
||||||
# cam = Camera()
|
if str(value) == "None":
|
||||||
# for subkey, subvalue in value.items():
|
value = None
|
||||||
# cam
|
elif key == "storage":
|
||||||
# for subkey, subvalue in value.items():
|
if str(value) == "None":
|
||||||
# setattr(cam, subkey, subvalue)
|
value = None
|
||||||
else:
|
else:
|
||||||
setattr(dev, key, value)
|
setattr(dev, key, value)
|
||||||
dev.save()
|
dev.save()
|
||||||
except yaml.YAMLError as exc:
|
except yaml.YAMLError as exc:
|
||||||
print(exc)
|
print(exc)
|
||||||
|
stream.close()
|
|
@ -4,62 +4,63 @@ from django.db import models
|
||||||
|
|
||||||
class Bluetooth(models.Model):
|
class Bluetooth(models.Model):
|
||||||
spec = models.CharField(max_length=100)
|
spec = models.CharField(max_length=100)
|
||||||
profiles = models.CharField(max_length=100)
|
profiles = models.CharField(max_length=100, blank=True, null=True)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f"{self.spec} - {self.profiles}"
|
return f"{self.spec} - {self.profiles}"
|
||||||
|
|
||||||
|
|
||||||
class Camera(models.Model):
|
class Camera(models.Model):
|
||||||
class FLASHES(models.TextChoices):
|
# class FLASHES(models.TextChoices):
|
||||||
LED = 'L', 'Led'
|
# LED = 'L', 'Led'
|
||||||
DUAL_LED = 'DL', 'Double Led'
|
# DUAL_LED = 'DL', 'Double Led'
|
||||||
|
|
||||||
|
flash = models.CharField(max_length=100)
|
||||||
megapixel = models.DecimalField(max_digits=5, decimal_places=1)
|
megapixel = models.DecimalField(max_digits=5, decimal_places=1)
|
||||||
flash = models.CharField(max_length=100, choices=FLASHES.choices)
|
info = models.CharField(max_length=100, null=True)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f"{self.megapixel} - {self.flash}"
|
return f" {self.flash - self.megapixel - self.info}"
|
||||||
|
|
||||||
|
|
||||||
class Device(models.Model):
|
class Device(models.Model):
|
||||||
architecture = models.JSONField(default=dict)
|
#architecture = models.JSONField(default=dict)
|
||||||
battery = models.JSONField(default=dict)
|
#battery = models.JSONField(default=dict)
|
||||||
before_install = models.JSONField(default=dict, null=True) # dict or str
|
#before_install = models.JSONField(default=dict, null=True) # dict or str
|
||||||
bluetooth = models.ForeignKey(Bluetooth, on_delete=models.CASCADE)
|
bluetooth = models.ForeignKey(Bluetooth, on_delete=models.CASCADE, null=True)
|
||||||
cameras = models.ManyToManyField(Camera)
|
cameras = models.ManyToManyField(Camera)
|
||||||
codename = models.CharField(max_length=100)
|
codename = models.CharField(max_length=100)
|
||||||
cpu = models.CharField(max_length=100)
|
cpu = models.CharField(max_length=100)
|
||||||
cpu_cores = models.IntegerField(default=1)
|
cpu_cores = models.CharField(max_length=100)
|
||||||
cpu_freq = models.CharField(max_length=100)
|
cpu_freq = models.CharField(max_length=1000)
|
||||||
current_branch = models.FloatField(default=None)
|
current_branch = models.FloatField(default=None, null=True)
|
||||||
custom_recovery_link = models.URLField(max_length=200, null=True)
|
custom_recovery_link = models.URLField(max_length=200, null=True)
|
||||||
download_boot = models.CharField(max_length=200)
|
download_boot = models.CharField(max_length=1000)
|
||||||
dimensions = models.JSONField(default=dict, null=True)
|
#dimensions = models.JSONField(default=dict, null=True)
|
||||||
gpu = models.CharField(max_length=100)
|
gpu = models.CharField(max_length=100)
|
||||||
image = models.CharField(max_length=100)
|
image = models.CharField(max_length=100)
|
||||||
install_method = models.CharField(max_length=100)
|
install_method = models.CharField(max_length=100)
|
||||||
is_ab_device = models.BooleanField(null=True)
|
is_ab_device = models.BooleanField(null=True)
|
||||||
kernel = models.CharField(max_length=100)
|
kernel = models.CharField(max_length=100)
|
||||||
maintainers = ArrayField(models.CharField(max_length=100), default=None)
|
maintainers = ArrayField(models.CharField(max_length=100), default=None, null=True)
|
||||||
device_models = ArrayField(models.CharField(max_length=100), default=None)
|
device_models = ArrayField(models.CharField(max_length=100), default=None, null=True)
|
||||||
name = models.CharField(max_length=100)
|
name = models.CharField(max_length=100)
|
||||||
network = ArrayField(models.CharField(max_length=100), default=None)
|
network = ArrayField(models.CharField(max_length=100), default=None, null=True)
|
||||||
peripherals = ArrayField(models.CharField(max_length=100), default=None)
|
peripherals = ArrayField(models.CharField(max_length=100, blank=True, null=True), default=None, blank=True, null=True)
|
||||||
ram = models.CharField(max_length=100)
|
ram = models.CharField(max_length=100)
|
||||||
recovery_boot = models.CharField(max_length=100)
|
recovery_boot = models.CharField(max_length=1000)
|
||||||
recovery_reboot = models.CharField(max_length=100)
|
recovery_reboot = models.CharField(max_length=100)
|
||||||
release = models.DateField()
|
#release = models.DateField()
|
||||||
screen = models.JSONField(default=dict) # dict or str
|
#screen = models.JSONField(default=dict) # dict or str
|
||||||
sdcard = models.JSONField(default=dict) # dict or str{1}
|
#sdcard = models.JSONField(default=dict) # dict or str{1}
|
||||||
soc = models.CharField(max_length=100)
|
soc = models.CharField(max_length=1000)
|
||||||
storage = models.CharField(max_length=100)
|
storage = models.CharField(max_length=100, blank=True)
|
||||||
tree = models.CharField(max_length=100)
|
tree = models.CharField(max_length=100)
|
||||||
device_type = models.CharField(max_length=100)
|
device_type = models.CharField(max_length=100)
|
||||||
uses_twrp = models.BooleanField(null=True)
|
uses_twrp = models.BooleanField(null=True)
|
||||||
vendor = models.CharField(max_length=100)
|
vendor = models.CharField(max_length=100)
|
||||||
vendor_short = models.CharField(max_length=100)
|
vendor_short = models.CharField(max_length=100)
|
||||||
versions = ArrayField(models.FloatField(default=None), default=None)
|
versions = ArrayField(models.FloatField(default=None), default=None, null=True)
|
||||||
wifi = models.CharField(max_length=200, null=True)
|
wifi = models.CharField(max_length=200, null=True)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
|
Loading…
Reference in a new issue