Advertisement
Guest User

Untitled

a guest
Apr 15th, 2014
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.85 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. ##----------------------------------------------------------------------
  3. ## geodecode
  4. ##----------------------------------------------------------------------
  5. ## Copyright (C) 2007-2014 The NOC Project
  6. ## See LICENSE for details
  7. ##----------------------------------------------------------------------
  8.  
  9. # Python modules
  10. import re
  11. import requests
  12. # NOC modules
  13. from noc.sa.models import *
  14. from noc.inv.models import *
  15. from noc.inv.models.object import *
  16.  
  17. rx_city = re.compile(
  18. r"^(г\.|пгт\.|пос\.|с\.)+(?P<city>(\S+ \S+ \S+|\S+ \S+|\S+))")
  19. rx_street = re.compile(
  20. r"^ ул\.+(?P<street>(\S+ \S+ \S+|\S+ \S+|\S+))")
  21. rx_house = re.compile(
  22. r"^ д\.+(?P<house>(\d+\S+|\d+))")
  23.  
  24. rx_room = re.compile(
  25. r"^ п\.+(?P<room>(\d+\S+|\d+))")
  26.  
  27. RegionName="Московский АО"
  28. CountryName="RU"
  29.  
  30. """
  31. Object(
  32. name = 'г.Москва, ул.Строителей, д.25',
  33. model = 'PoP | Access',
  34. data = {"container": {"container": True},
  35. "geopoint":{
  36. "layer": "pop_access",
  37. "srid": "EPSG:4326",
  38. "x": 1,
  39. "y": 2},
  40. "pop":{"level": 20}}
  41. ).save
  42. quit()
  43. """
  44.  
  45. K = 0
  46. k = 0
  47.  
  48. for mo in tuple(ManagedObject.objects.filter(
  49. administrative_domain=1)):
  50. mo_id = mo.id
  51. name = mo.name
  52. postaddress = mo.postaddress.encode("UTF-8")
  53. #
  54. # print ""
  55. # print postaddress
  56. #
  57. postaddress = postaddress.split(',')
  58. match = rx_city.search(postaddress[0])
  59. if match:
  60. city = match.group("city")
  61. else:
  62. continue
  63. try:
  64. match = rx_street.search(postaddress[1])
  65. except IndexError:
  66. continue
  67. if match:
  68. street = match.group("street")
  69. else:
  70. continue
  71. try:
  72. match = rx_house.search(postaddress[2])
  73. except IndexError:
  74. continue
  75. if match:
  76. house = match.group("house")
  77. else:
  78. continue
  79. try:
  80. match = rx_room.search(postaddress[3])
  81. except IndexError:
  82. continue
  83. if match:
  84. room = match.group("room")
  85. else:
  86. continue
  87.  
  88. pop = 'г.' + city + ', ул.' + street + ', д.' + house
  89. room = "Подъезд №" + room
  90.  
  91. K += 1
  92. if city:
  93. print pop
  94. print room
  95. print "Rack 7U"
  96.  
  97. try:
  98. url="http://geocode-maps.yandex.ru/1.x/?geocode=" + city + ",+" + street.replace(' ', '+') + ",+дом+" + house +"&format=json"
  99. urlopen = requests.get(url)
  100. obj = urlopen.json()
  101. coord = obj["response"]["GeoObjectCollection"]["featureMember"][0]["GeoObject"]["Point"]["pos"].split(' ')
  102. x = coord[0]
  103. y = coord[1]
  104.  
  105. print str(y), str(x), name
  106. print "\n\n"
  107.  
  108. k += 1
  109. except:
  110. continue
  111.  
  112. print K, k
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement