Skip to content

Commit

Permalink
Merge branch 'master' of github.com:rduivenvoorde/pdokservicesplugin
Browse files Browse the repository at this point in the history
  • Loading branch information
rduivenvoorde committed Aug 15, 2014
2 parents 90841d6 + 2995b1f commit 023af6c
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion pdokgeocoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import urllib
import urllib2
from xml.dom.minidom import parse
from PyQt4 import QtCore

searchstring = 'riouwstaat, haarlem'
#searchstring = 'kenaustraat 12, haarlem'
Expand All @@ -19,6 +20,26 @@
#searchstring = '2022ZJ'
#searchstring = '2022ZJ 23'

# Set Proxy from QGIS-Settings
def setup_urllib2():
# TODO: test with different proxy settings
settings = QtCore.QSettings()

if settings.value("/proxy/proxyEnabled"):
proxyHost = str(settings.value("proxy/proxyHost", unicode()))
proxyPassword = str(settings.value("proxy/proxyPassword", unicode()))
proxyPort = str(settings.value("proxy/proxyPort", unicode()))
proxyType = str(settings.value("proxy/proxyType", unicode()))
proxyTypes = { 'DefaultProxy' : 'http', 'HttpProxy' : 'http', 'Socks5Proxy' : 'socks', 'HttpCachingProxy' : 'http', 'FtpCachingProxy' : 'ftp' }
if proxyType in proxyTypes:
proxyType = proxyTypes[proxyType]
proxyUser = str(settings.value("proxy/proxyUser", unicode()))
proxyString = 'http://' + proxyUser + ':' + proxyPassword + '@' + proxyHost + ':' + proxyPort
proxy = urllib2.ProxyHandler({proxyType : proxyString})
auth = urllib2.HTTPBasicAuthHandler()
opener = urllib2.build_opener(proxy, auth, urllib2.HTTPHandler)
urllib2.install_opener(opener)

def search(searchstring):
"""
Expand All @@ -31,7 +52,8 @@ def search(searchstring):
#print url
addressesarray = []
try:
response = urllib.urlopen(url)
setup_urllib2()
response = urllib2.urlopen(url)
if response.code != 200:
print 'ERROR %s' % response.code
exit()
Expand Down

0 comments on commit 023af6c

Please sign in to comment.