34 linhas
1,1 KiB
Python
34 linhas
1,1 KiB
Python
import json
|
|
import re
|
|
import sys
|
|
|
|
from django.core.management.base import BaseCommand, CommandError
|
|
from django.contrib.auth import get_user_model
|
|
|
|
from rxmapp.models import RapportoRicezione, TipoRadio
|
|
|
|
|
|
class Command(BaseCommand):
|
|
help = "Closes the specified poll for voting"
|
|
date_re = re.compile(r"\d\d\d\d-\d\d-\d\d")
|
|
|
|
def add_arguments(self, parser):
|
|
pass
|
|
|
|
def handle(self, *args, **options):
|
|
data = json.load(sys.stdin)
|
|
user = get_user_model().objects.filter(is_superuser=True).first()
|
|
tiporadio = TipoRadio.objects.all().first()
|
|
cnt = 0
|
|
for rapporto_in in data["rapporti"]:
|
|
rdata = {
|
|
"author": user,
|
|
"tipo_radio": tiporadio,
|
|
"created": self.date_re.search(rapporto_in["explaination"]).group(0),
|
|
}
|
|
for key in ("lat", "lng", "comprensibile", "stabilita"):
|
|
rdata[key] = rapporto_in[key]
|
|
r, created = RapportoRicezione.objects.get_or_create(**rdata)
|
|
if created:
|
|
cnt += 1
|
|
self.stdout.write(self.style.SUCCESS("%d rapporti importati" % cnt))
|