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

progress bar

parent a13bb3e8
Aucune branche associée trouvée
Aucune étiquette associée trouvée
2 requêtes de fusion!158Attempt at fixing tests in the restructure branch,!157WIP - Restructure the repository
...@@ -19,24 +19,40 @@ ...@@ -19,24 +19,40 @@
# Copyright (C) 2013 Laurent Peuch <cortex@worlddomination.be> # Copyright (C) 2013 Laurent Peuch <cortex@worlddomination.be>
# Copyright (C) 2015 Arnaud Fabre <af@laquadrature.net> # Copyright (C) 2015 Arnaud Fabre <af@laquadrature.net>
import json
import ijson
import pyprind
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
from django.conf import settings from django.conf import settings
from urllib2 import urlopen from urllib2 import urlopen
import ijson
from representatives.models import Representative from representatives.models import Representative
from representatives.utils import import_a_representative from representatives.utils import import_a_representative
class Command(BaseCommand): class Command(BaseCommand):
def handle(self, *args, **options): def handle(self, *args, **options):
compotista_server = getattr(settings,
Representative.objects.all().delete()
self.compotista_server = getattr(settings,
'COMPOTISTA_SERVER', 'COMPOTISTA_SERVER',
'http://compotista.mm.staz.be') 'http://compotista.mm.staz.be')
url = compotista_server + '/export/latest/' url = self.compotista_server + '/export/latest/'
print('Import representatives from %s' % url) print('Import representatives from %s' % url)
bar = pyprind.ProgBar(self.get_number_of_meps())
resource = urlopen(url) resource = urlopen(url)
Representative.objects.all().delete() for i, representative in enumerate(ijson.items(resource, 'item')):
for representative in ijson.items(resource, 'item'): representative = import_a_representative(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.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter