Skip to content
Extraits de code Groupes Projets
Valider 66cbcf4c rédigé par luxcem's avatar luxcem
Parcourir les fichiers

progress bar

parent a13bb3e8
Branches
Étiquettes
Aucune requête de fusion associée trouvée
......@@ -19,24 +19,40 @@
# Copyright (C) 2013 Laurent Peuch <cortex@worlddomination.be>
# Copyright (C) 2015 Arnaud Fabre <af@laquadrature.net>
import json
import ijson
import pyprind
from django.core.management.base import BaseCommand
from django.conf import settings
from urllib2 import urlopen
import ijson
from representatives.models import Representative
from representatives.utils import import_a_representative
class Command(BaseCommand):
def handle(self, *args, **options):
compotista_server = getattr(settings,
Representative.objects.all().delete()
self.compotista_server = getattr(settings,
'COMPOTISTA_SERVER',
'http://compotista.mm.staz.be')
url = compotista_server + '/export/latest/'
url = self.compotista_server + '/export/latest/'
print('Import representatives from %s' % url)
bar = pyprind.ProgBar(self.get_number_of_meps())
resource = urlopen(url)
Representative.objects.all().delete()
for representative in ijson.items(resource, 'item'):
import_a_representative(representative)
for i, representative in enumerate(ijson.items(resource, 'item')):
representative = import_a_representative(representative)
representative_id = '{} - {}'.format(i, representative.full_name.encode('utf-8'))
bar.update(item_id = representative_id)
print(bar)
def get_number_of_meps(self):
response = urlopen(self.compotista_server + '/api/representatives/')
return int(json.load(response).get('count'))
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter