Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update 'add_ons_to_gss' command to support CSVReader for Python 2 #244

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 19 additions & 10 deletions mapit_gb/management/commands/mapit_UK_add_ons_to_gss.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import codecs
import csv
import os.path
import sys
from django.core.management.base import NoArgsCommand
from mapit.models import Area, CodeType
from psycopg2 import IntegrityError
Expand All @@ -30,22 +31,30 @@ class Command(NoArgsCommand):
help = 'Inserts the old ONS codes into mapit'

def handle_noargs(self, **options):
code_changes = codecs.open(os.path.join(
python_version = sys.version_info[0]

code_change_file_path = os.path.join(
os.path.dirname(__file__),
'../../data/BL-2010-10-code-change.csv'
), 'r', 'latin-1')
mapping = csv.reader(code_changes)
'../../data/BL-2010-10-code-change.csv')
if python_version < 3:
mapping = csv.reader(open(code_change_file_path))
else:
code_changes = codecs.open(code_change_file_path, 'r', 'latin-1')
mapping = csv.reader(code_changes)
next(mapping)
for row in mapping:
new_code, name, old_code = row[0], row[1], row[3]
new_code, old_code = row[0], row[3]
process(new_code, old_code)

missing_codes = codecs.open(os.path.join(
missing_codes_file_path = os.path.join(
os.path.dirname(__file__),
'../../data/BL-2010-10-missing-codes.csv'
), 'r', 'latin-1')
mapping = csv.reader(missing_codes)
'../../data/BL-2010-10-missing-codes.csv')
if python_version < 3:
mapping = csv.reader(open(missing_codes_file_path))
else:
missing_codes = codecs.open(missing_codes_file_path, 'r', 'latin-1')
mapping = csv.reader(missing_codes)
next(mapping)
for row in mapping:
type, new_code, old_code, name = row
new_code, old_code = row[1], row[2]
process(new_code, old_code)