# -*- coding: utf-8 -*-
# Generated by Django 1.10.5 on 2017-02-04 21:00
from __future__ import unicode_literals

from django.db import migrations, models

from tn_parser.transport.models import DataProviderTypes

CATALOG_API_REF = 'https://catalog.api.2gis.ru/2.0/transport/route/get?id='


route_api_id = {
    '1': '10837392193749035',
    '1cr': '10837392193749035',
    '1a': '10837392193748993',
    '2': '10837392193748998',
    '2k': '10837392193749034',
    '4': '10837392193749006',
    '5': '10837392193749009',
    '6': '10837392193749013',
    '7': '10837392193749016',
    '7a': '10837392193749020',
    '8a': '10837392193749024',
    '8': '10837392193749022',
    '9': '10837392193749019',
    '9a': '10837392193749033',
    '10': '10837392193749014',
    '11': '10837392193749010',
    '12': '10837392193749008',
    '13': '10837392193748999',
    '14': '10837392193749003',
    '15a': '10837392193749005',
    '16': '10837392193749033',
    '17': '10837392193749018',
    '17a': '10837392193749021',
    '18': '10837392193749023',
    '19': '10837392193749025',
    '20': '10837392193749029',
    '22': '10837392193749030',
    '24': '10837392193749031',
    '26': '10837392193749032',
    '27': '10837392193749028',
    '27a': '10837392235781355',
    '35': '10837392193749017',
    '35a': '10837392193749012',
    '101': '10837392193748995',
    '1t': '10837392193748994',
    '2t': '10837392193748997',
    '3t': '10837392193749000',
}


def forwards_func(apps, schema_editor):
    DataProviderUrl = apps.get_model("transport", "DataProviderUrl")

    data_urls = []
    for rt_code, rt_id in iter(route_api_id.items()):
        if rt_id:
            data_urls.append(
                DataProviderUrl(
                    route_code=rt_code,
                    link='{}{}'.format(CATALOG_API_REF, rt_id),
                    type=DataProviderTypes.TWOGIS_ROUTE_API,
                )
            )

    db_alias = schema_editor.connection.alias
    DataProviderUrl.objects.using(db_alias).bulk_create(data_urls)


def reverse_func(apps, schema_editor):
    DataProviderUrl = apps.get_model("transport", "DataProviderUrl")

    db_alias = schema_editor.connection.alias
    DataProviderUrl.objects.using(db_alias)\
        .filter(
            route_code__in=route_api_id.keys(),
            type=DataProviderTypes.TWOGIS_ROUTE_API)\
        .delete()


class Migration(migrations.Migration):

    dependencies = [
        ('transport', '0002_add_routes_data_url'),
    ]

    operations = [
        migrations.RunPython(forwards_func, reverse_func),
    ]


bd40c032a1b520d3e90528079627dacf663f70a1
<mask token>


def reverse_func(apps, schema_editor):
    DataProviderUrl = apps.get_model('transport', 'DataProviderUrl')
    db_alias = schema_editor.connection.alias
    DataProviderUrl.objects.using(db_alias).filter(route_code__in=
        route_api_id.keys(), type=DataProviderTypes.TWOGIS_ROUTE_API).delete()


class Migration(migrations.Migration):
    dependencies = [('transport', '0002_add_routes_data_url')]
    operations = [migrations.RunPython(forwards_func, reverse_func)]

<mask token>


def forwards_func(apps, schema_editor):
    DataProviderUrl = apps.get_model('transport', 'DataProviderUrl')
    data_urls = []
    for rt_code, rt_id in iter(route_api_id.items()):
        if rt_id:
            data_urls.append(DataProviderUrl(route_code=rt_code, link=
                '{}{}'.format(CATALOG_API_REF, rt_id), type=
                DataProviderTypes.TWOGIS_ROUTE_API))
    db_alias = schema_editor.connection.alias
    DataProviderUrl.objects.using(db_alias).bulk_create(data_urls)


def reverse_func(apps, schema_editor):
    DataProviderUrl = apps.get_model('transport', 'DataProviderUrl')
    db_alias = schema_editor.connection.alias
    DataProviderUrl.objects.using(db_alias).filter(route_code__in=
        route_api_id.keys(), type=DataProviderTypes.TWOGIS_ROUTE_API).delete()


class Migration(migrations.Migration):
    dependencies = [('transport', '0002_add_routes_data_url')]
    operations = [migrations.RunPython(forwards_func, reverse_func)]

<mask token>
CATALOG_API_REF = 'https://catalog.api.2gis.ru/2.0/transport/route/get?id='
route_api_id = {'1': '10837392193749035', '1cr': '10837392193749035', '1a':
    '10837392193748993', '2': '10837392193748998', '2k':
    '10837392193749034', '4': '10837392193749006', '5': '10837392193749009',
    '6': '10837392193749013', '7': '10837392193749016', '7a':
    '10837392193749020', '8a': '10837392193749024', '8':
    '10837392193749022', '9': '10837392193749019', '9a':
    '10837392193749033', '10': '10837392193749014', '11':
    '10837392193749010', '12': '10837392193749008', '13':
    '10837392193748999', '14': '10837392193749003', '15a':
    '10837392193749005', '16': '10837392193749033', '17':
    '10837392193749018', '17a': '10837392193749021', '18':
    '10837392193749023', '19': '10837392193749025', '20':
    '10837392193749029', '22': '10837392193749030', '24':
    '10837392193749031', '26': '10837392193749032', '27':
    '10837392193749028', '27a': '10837392235781355', '35':
    '10837392193749017', '35a': '10837392193749012', '101':
    '10837392193748995', '1t': '10837392193748994', '2t':
    '10837392193748997', '3t': '10837392193749000'}


def forwards_func(apps, schema_editor):
    DataProviderUrl = apps.get_model('transport', 'DataProviderUrl')
    data_urls = []
    for rt_code, rt_id in iter(route_api_id.items()):
        if rt_id:
            data_urls.append(DataProviderUrl(route_code=rt_code, link=
                '{}{}'.format(CATALOG_API_REF, rt_id), type=
                DataProviderTypes.TWOGIS_ROUTE_API))
    db_alias = schema_editor.connection.alias
    DataProviderUrl.objects.using(db_alias).bulk_create(data_urls)


def reverse_func(apps, schema_editor):
    DataProviderUrl = apps.get_model('transport', 'DataProviderUrl')
    db_alias = schema_editor.connection.alias
    DataProviderUrl.objects.using(db_alias).filter(route_code__in=
        route_api_id.keys(), type=DataProviderTypes.TWOGIS_ROUTE_API).delete()


class Migration(migrations.Migration):
    dependencies = [('transport', '0002_add_routes_data_url')]
    operations = [migrations.RunPython(forwards_func, reverse_func)]

from __future__ import unicode_literals
from django.db import migrations, models
from tn_parser.transport.models import DataProviderTypes
CATALOG_API_REF = 'https://catalog.api.2gis.ru/2.0/transport/route/get?id='
route_api_id = {'1': '10837392193749035', '1cr': '10837392193749035', '1a':
    '10837392193748993', '2': '10837392193748998', '2k':
    '10837392193749034', '4': '10837392193749006', '5': '10837392193749009',
    '6': '10837392193749013', '7': '10837392193749016', '7a':
    '10837392193749020', '8a': '10837392193749024', '8':
    '10837392193749022', '9': '10837392193749019', '9a':
    '10837392193749033', '10': '10837392193749014', '11':
    '10837392193749010', '12': '10837392193749008', '13':
    '10837392193748999', '14': '10837392193749003', '15a':
    '10837392193749005', '16': '10837392193749033', '17':
    '10837392193749018', '17a': '10837392193749021', '18':
    '10837392193749023', '19': '10837392193749025', '20':
    '10837392193749029', '22': '10837392193749030', '24':
    '10837392193749031', '26': '10837392193749032', '27':
    '10837392193749028', '27a': '10837392235781355', '35':
    '10837392193749017', '35a': '10837392193749012', '101':
    '10837392193748995', '1t': '10837392193748994', '2t':
    '10837392193748997', '3t': '10837392193749000'}


def forwards_func(apps, schema_editor):
    DataProviderUrl = apps.get_model('transport', 'DataProviderUrl')
    data_urls = []
    for rt_code, rt_id in iter(route_api_id.items()):
        if rt_id:
            data_urls.append(DataProviderUrl(route_code=rt_code, link=
                '{}{}'.format(CATALOG_API_REF, rt_id), type=
                DataProviderTypes.TWOGIS_ROUTE_API))
    db_alias = schema_editor.connection.alias
    DataProviderUrl.objects.using(db_alias).bulk_create(data_urls)


def reverse_func(apps, schema_editor):
    DataProviderUrl = apps.get_model('transport', 'DataProviderUrl')
    db_alias = schema_editor.connection.alias
    DataProviderUrl.objects.using(db_alias).filter(route_code__in=
        route_api_id.keys(), type=DataProviderTypes.TWOGIS_ROUTE_API).delete()


class Migration(migrations.Migration):
    dependencies = [('transport', '0002_add_routes_data_url')]
    operations = [migrations.RunPython(forwards_func, reverse_func)]

# -*- coding: utf-8 -*-
# Generated by Django 1.10.5 on 2017-02-04 21:00
from __future__ import unicode_literals

from django.db import migrations, models

from tn_parser.transport.models import DataProviderTypes

CATALOG_API_REF = 'https://catalog.api.2gis.ru/2.0/transport/route/get?id='


route_api_id = {
    '1': '10837392193749035',
    '1cr': '10837392193749035',
    '1a': '10837392193748993',
    '2': '10837392193748998',
    '2k': '10837392193749034',
    '4': '10837392193749006',
    '5': '10837392193749009',
    '6': '10837392193749013',
    '7': '10837392193749016',
    '7a': '10837392193749020',
    '8a': '10837392193749024',
    '8': '10837392193749022',
    '9': '10837392193749019',
    '9a': '10837392193749033',
    '10': '10837392193749014',
    '11': '10837392193749010',
    '12': '10837392193749008',
    '13': '10837392193748999',
    '14': '10837392193749003',
    '15a': '10837392193749005',
    '16': '10837392193749033',
    '17': '10837392193749018',
    '17a': '10837392193749021',
    '18': '10837392193749023',
    '19': '10837392193749025',
    '20': '10837392193749029',
    '22': '10837392193749030',
    '24': '10837392193749031',
    '26': '10837392193749032',
    '27': '10837392193749028',
    '27a': '10837392235781355',
    '35': '10837392193749017',
    '35a': '10837392193749012',
    '101': '10837392193748995',
    '1t': '10837392193748994',
    '2t': '10837392193748997',
    '3t': '10837392193749000',
}


def forwards_func(apps, schema_editor):
    DataProviderUrl = apps.get_model("transport", "DataProviderUrl")

    data_urls = []
    for rt_code, rt_id in iter(route_api_id.items()):
        if rt_id:
            data_urls.append(
                DataProviderUrl(
                    route_code=rt_code,
                    link='{}{}'.format(CATALOG_API_REF, rt_id),
                    type=DataProviderTypes.TWOGIS_ROUTE_API,
                )
            )

    db_alias = schema_editor.connection.alias
    DataProviderUrl.objects.using(db_alias).bulk_create(data_urls)


def reverse_func(apps, schema_editor):
    DataProviderUrl = apps.get_model("transport", "DataProviderUrl")

    db_alias = schema_editor.connection.alias
    DataProviderUrl.objects.using(db_alias)\
        .filter(
            route_code__in=route_api_id.keys(),
            type=DataProviderTypes.TWOGIS_ROUTE_API)\
        .delete()


class Migration(migrations.Migration):

    dependencies = [
        ('transport', '0002_add_routes_data_url'),
    ]

    operations = [
        migrations.RunPython(forwards_func, reverse_func),
    ]

