-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathuldk_teryt.py
executable file
·33 lines (29 loc) · 1.05 KB
/
uldk_teryt.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from urllib.parse import urlencode
from PyQt5.QtNetwork import QNetworkRequest, QNetworkAccessManager, QNetworkReply
from qgis.PyQt.QtCore import QUrl, QEventLoop
from qgis.core import QgsVectorLayer, QgsGeometry, QgsFeature, QgsProject
URL = "http://uldk.gugik.gov.pl/"
def getRequestTeryt(xy, request):
def handleReply(reply):
""""""
nonlocal result
nonlocal loop
if reply.error() == QNetworkReply.NoError:
data = reply.readAll().data().decode('utf-8')
if data[0] !='0':
return
if ";" in data:
result = data.split('\n')[1].split(';')[1]
else:
result = data.split('\n')[1]
loop.quit()
PARAMS = {'request': request, 'xy': xy, 'result': 'teryt'}
url = URL + "?" + urlencode(PARAMS)
result = None
request = QNetworkRequest(QUrl(url))
manager = QNetworkAccessManager()
reply = manager.get(request)
reply.finished.connect(lambda: handleReply(reply))
loop = QEventLoop()
loop.exec_()
return result