Commit 82902ba4 authored by njoyard's avatar njoyard Committed by GitHub

Merge pull request #36 from political-memory/chamber-helper

Add francedata chamber creation helper
parents f2d3ba3e 2517fe20
......@@ -90,6 +90,18 @@ class GenericImporter(object):
return (instance, created)
def ensure_chambers():
"""
Ensures chambers are created
"""
france = Country.objects.get(name="France")
for key in ('AN', 'SEN'):
variant = FranceDataVariants[key]
Chamber.objects.get_or_create(name=variant['chamber'],
abbreviation=variant['abbreviation'],
country=france)
class FranceDataImporter(GenericImporter):
url = 'http://francedata.future/data/parlementaires.json'
......@@ -99,9 +111,7 @@ class FranceDataImporter(GenericImporter):
def __init__(self, variant):
self.france = Country.objects.get(name="France")
self.variant = FranceDataVariants[variant]
self.chamber, _ = Chamber.objects.get_or_create(
name=self.variant['chamber'],
abbreviation=self.variant['abbreviation'], country=self.france)
self.chamber = Chamber.objects.get(name=self.variant['chamber'])
self.ch_constituency, _ = Constituency.objects.get_or_create(
name=self.variant['chamber'], country=self.france)
......@@ -311,6 +321,8 @@ def main(stream=None):
if not apps.ready:
django.setup()
ensure_chambers()
an_importer = FranceDataImporter('AN')
GenericImporter.pre_import(an_importer)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment