Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- ##----------------------------------------------------------------------
- ## geodecode
- ##----------------------------------------------------------------------
- ## Copyright (C) 2007-2014 The NOC Project
- ## See LICENSE for details
- ##----------------------------------------------------------------------
- # Python modules
- import re
- import requests
- # NOC modules
- from noc.sa.models import *
- from noc.inv.models import *
- from noc.inv.models.object import *
- rx_city = re.compile(
- r"^(г\.|пгт\.|пос\.|с\.)+(?P<city>(\S+ \S+ \S+|\S+ \S+|\S+))")
- rx_street = re.compile(
- r"^ ул\.+(?P<street>(\S+ \S+ \S+|\S+ \S+|\S+))")
- rx_house = re.compile(
- r"^ д\.+(?P<house>(\d+\S+|\d+))")
- rx_room = re.compile(
- r"^ п\.+(?P<room>(\d+\S+|\d+))")
- K = 0
- k = 0
- for mo in tuple(ManagedObject.objects.filter(
- administrative_domain=1)):
- mo_id = mo.id
- name = mo.name
- postaddress = mo.postaddress.encode("UTF-8")
- #
- print ""
- # print postaddress
- #
- postaddress = postaddress.split(',')
- match = rx_city.search(postaddress[0])
- if match:
- city = match.group("city")
- #
- #
- else:
- continue
- try:
- match = rx_street.search(postaddress[1])
- except IndexError:
- continue
- if match:
- street = match.group("street")
- else:
- continue
- try:
- match = rx_house.search(postaddress[2])
- except IndexError:
- continue
- if match:
- house = match.group("house")
- else:
- continue
- try:
- match = rx_room.search(postaddress[3])
- except IndexError:
- continue
- if match:
- room = match.group("room")
- else:
- continue
- pop = 'г.' + city + ', ул.' + street + ', д.' + house
- room = "Подъезд №" + room
- K += 1
- if city:
- print 'PoP = ', pop
- print 'room = ', room
- try:
- url="http://geocode-maps.yandex.ru/1.x/?geocode=" + city + ",+" + street.replace(' ', '+') + ",+дом+" + house +"&format=json"
- urlopen = requests.get(url)
- obj = urlopen.json()
- coord = obj["response"]["GeoObjectCollection"]["featureMember"][0]["GeoObject"]["Point"]["pos"].split(' ')
- x = coord[0]
- y = coord[1]
- print 'x = ', x
- print 'y = ', y
- print name,"\n"
- k += 1
- except:
- continue
- print K, k
Advertisement
Add Comment
Please, Sign In to add comment