Example #1
0
 def create(self, data, user):
     serializer = AddressSerializer(data=data)
     serializer.is_valid()
     if serializer.is_valid():
         serializer.save(street=normalize_street(data['street']),
                         city=normalize_city(data['city']))
         return serializer.data
     else:
         raise ServiceException(serializer.errors)
Example #2
0
 def update(self, instance, data, user):
     serializer = AddressSerializer(instance=instance,
                                    data=data,
                                    partial=True)
     if serializer.is_valid():
         serializer.save(street=normalize_street(data['street']),
                         city=normalize_city(data['city']))
         return serializer.data
     else:
         raise ServiceException(serializer.errors)
Example #3
0
def houses_info():
    rb = xlrd.open_workbook(
        os.path.join(settings.MEDIA_ROOT, 'temp', 'houses.xlsx'))
    sheet = rb.sheet_by_index(0)
    for rownum in range(3, sheet.nrows):
        area = sheet.cell(rownum, 0).value.strip()
        city = normalize_city(sheet.cell(rownum, 2).value.strip())
        street = normalize_street(sheet.cell(rownum, 3).value.strip())
        number = normalize_number(
            str(sheet.cell(rownum, 4).value).strip().replace('.0', ''))
        year_of_building = None
        number_of_apartments = None
        total_area = None
        residential_premises_area = None
        nonresidential_premises_area = None
        if type(sheet.cell(rownum, 5).value) == float:
            year_of_building = int(sheet.cell(rownum, 5).value)
        if type(sheet.cell(rownum, 6).value) == float:
            number_of_apartments = int(sheet.cell(rownum, 6).value)
        if type(sheet.cell(rownum, 7).value) == float:
            total_area = float(sheet.cell(rownum, 7).value)
        if type(sheet.cell(rownum, 8).value) == float:
            residential_premises_area = float(sheet.cell(rownum, 8).value)
        if type(sheet.cell(rownum, 9).value) == float:
            nonresidential_premises_area = float(sheet.cell(rownum, 9).value)
        try:
            house = House.objects.get(address__area=area,
                                      address__city=city,
                                      address__street=street,
                                      number=number)
        except House.DoesNotExist:
            print(f'{area}, {city}, {street}, {number}')
        if house.year_of_building is None or house.year_of_building == 0:
            house.year_of_building = year_of_building
        if house.number_of_apartments is None or house.number_of_apartments == 0:
            house.number_of_apartments = number_of_apartments
        if house.total_area is None or house.total_area == 0:
            house.total_area = total_area
        if house.residential_premises_area is None or house.residential_premises_area == 0:
            house.residential_premises_area = residential_premises_area
        if house.nonresidential_premises_area is None or house.nonresidential_premises_area == 0:
            house.nonresidential_premises_area = nonresidential_premises_area
        house.save()
Example #4
0
def houses():
    """Выгрузка информации из реестра лицензий"""
    f = open(os.path.join(settings.MEDIA_ROOT, 'temp',
                          'reestr_licensing.xlsx'),
             "wb+")  # открываем файл для записи, в режиме wb
    ufr = requests.get(
        "https://iggn.permkrai.ru/download.php?id=1621")  # делаем запрос
    f.write(ufr.content
            )  # записываем содержимое в файл; как видите - content запроса
    f.close()
    rb = xlrd.open_workbook(
        os.path.join(settings.MEDIA_ROOT, 'temp', 'reestr_licensing.xlsx'))
    sheet = rb.sheet_by_index(1)
    for rownum in range(6, sheet.nrows):
        if sheet.cell(rownum, 0).value == '':
            continue
        #print(sheet.cell(rownum, 0).value)
        # адрес дома
        number = normalize_number(
            str(sheet.cell(rownum, 6).value).strip().lower().replace('.0', ''))
        street, comm = cut_value(sheet.cell(rownum, 5).value, '')
        street = normalize_street(street)
        if 'Блочная' in street:
            street = 'ул. Блочная'
        city = normalize_city(sheet.cell(rownum, 4).value.strip())
        city = city.replace('р.п.', 'п.')
        if street == 'ул. Новоселовой':
            street = 'ул. Новоселова'
        if street == '' and city == 'г. Пермь':
            continue
        area = sheet.cell(rownum, 3).value.strip()
        if area == 'льская' and city == 'г. Березники':
            area = 'Березниковский городской округ'

        # print(f'{area} {city} {street} {number}')
        addr = Address.objects.filter(area__contains=area,
                                      city=city,
                                      street=street).first()
        if addr is None:
            print(
                f'Не найден адрес {area}, {city}, {street} в строке {rownum}')
            continue
        house, created = House.objects.get_or_create(address_id=addr.id,
                                                     number=number)
        # организация
        if sheet.cell(rownum, 8).value == ' ' or sheet.cell(rownum,
                                                            8).value == '':
            inn = str(sheet.cell(rownum, 1).value).strip().replace('.0', '')
            name = sheet.cell(rownum, 2).value.strip()
            org, created = Organization.objects.get_or_create(inn=inn)
            if created:
                org.name = name
                org.save()
            elif name != org.name:
                org.old_name = org.name
                org.date_of_changind_name = datetime.now().date()
                org.name = name
                org.save()
            house.license_registry_organization = org
            house.save()
        else:
            house.license_registry_organization = None
            house.save()

        for n in Notify.objects.filter(house=house, status_id=3):
            if sheet.cell(rownum, 8).value == ' ' or sheet.cell(rownum,
                                                                8).value == '':
                n.same_organization_in_license_registry = n.organization == org
                n.save_without_historical_record()
            else:
                n.same_organization_in_license_registry = None
                n.save_without_historical_record()
Example #5
0
def regional_program(path):
    """Выгрузка информации о домах из реестра капитального ремонта"""
    for h in House.objects.all():
        h.included_in_the_regional_program = False
        h.save()
    rb = xlrd.open_workbook(path)
    sheet = rb.sheet_by_index(0)
    errors = []
    for rownum in range(3, sheet.nrows):
        if sheet.cell(rownum, 1).value == '':
            continue
        area = str(sheet.cell(rownum, 1).value).strip()
        area = area.replace('Березники', 'Березниковский').replace(
            'Пермь', 'Пермский').replace('Лысьва', 'Лысьвенский')
        city = str(sheet.cell(rownum, 2).value).strip()
        city = city.replace('д. Ваньки', 'с. Ваньки').replace('с. Большой Букор','д. Большой Букор')\
            .replace('Белоборово','Белобородово')
        city = normalize_city(city)
        street = str(sheet.cell(rownum, 3).value).strip()
        street = normalize_street(street)

        city = city.replace('ЗАТО Звездный', 'пгт. Звездный').replace(
            'д. Берег Камы (Юго-Камское г/п)', 'д. Берег Камы')
        if city == 'г. Усолье' or city == 'п. Железнодорожный' or city == 'с. Пыскор':
            area = 'Усольский муниципальный район'
        elif city == 'г. Чусовой, п. Лямино':
            city = 'п. Лямино'
        elif 'п. Новые Ляды' in city:
            city = 'г. Пермь'
            street = street.replace('ул. 40-летия Победы', 'ул. 40 лет Победы (Новые Ляды)')\
                .replace('ул. Веселая', 'ул. Веселая (Новые Ляды)')\
                .replace('ул. Мира', 'ул. Мира (Новые Ляды)') \
                .replace('ул. Молодежная', 'ул. Молодежная (Новые Ляды)') \
                .replace('ул. Островского', 'ул. Островского (Новые Ляды)')\
                .replace('ул. Чусовская', 'ул. Чусовская (Новые Ляды)')
        elif city == 'с. Григорьевское':
            street = street.replace('пл. Советская', 'ул. Советская')
        elif city == 'п. Октябрьский':
            street = street.replace('ул. Крупской', 'ул. Крупская')
        elif city == 'г. Чердынь':
            street = street.replace('пер. Сарапулова',
                                    'ул. Сарапулова').replace(
                                        'мкр. АК-5', 'ул. АТК')

        number = normalize_number(
            str(sheet.cell(rownum, 4).value).strip().replace('.0', '').lower())
        try:
            address = Address.objects.get(area__icontains=area,
                                          city__iexact=city,
                                          street__iexact=street)
            house, created = House.objects.get_or_create(address_id=address.id,
                                                         number__iexact=number)
            house.included_in_the_regional_program = True
            house.save()
        except (Address.DoesNotExist, Address.MultipleObjectsReturned):
            errors += [
                f'Не найдена улица {area}, {city}, {street} в строке {rownum+1}'
            ]
        except House.DoesNotExist:
            errors += [
                f'Не найден дом {area}, {city}, {street}, {number} в строке {rownum+1}'
            ]
        except House.MultipleObjectsReturned:
            errors += [
                f'Найдено несколько домов {area}, {city}, {street}, {number}'
            ]
    return errors