Skip to content

Commit

Permalink
set a custom user agent for python requests
Browse files Browse the repository at this point in the history
  • Loading branch information
ltclm committed Dec 8, 2016
1 parent 655af13 commit c08d2a3
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion chsdi/lib/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def make_geoadmin_url(request, agnostic=False):
return base_url


def resource_exists(path, headers={}):
def resource_exists(path, headers={'User-Agent': 'mf-geoadmin/python'}):
try:
r = requests.head(path, headers=headers)
except ConnectionError:
Expand Down
4 changes: 2 additions & 2 deletions chsdi/templates/htmlpopup/cadastralwebmap_opendata.mako
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ ${partials.table_body_cadastral(c, lang, fallbackLang, clickCoord)}
</tr>
<tr>
<td class="cell-left">${_('ch.swisstopo-vd.amtliche-vermessung.shape')}</td><td>
% if requests.get(shp_url).status_code == 200:
% if requests.head(shp_url, headers={'User-Agent': 'mf-geoadmin/python'}).status_code == 200:
<a href="${shp_url}" target="_blank">
SHP</a>
% else:
Expand All @@ -60,7 +60,7 @@ ${partials.table_body_cadastral(c, lang, fallbackLang, clickCoord)}
</tr>
<tr>
<td class="cell-left">${_('ch.swisstopo-vd.amtliche-vermessung.itf')}</td><td>
% if requests.get(itf_url).status_code == 200:
% if requests.head(itf_url, headers={'User-Agent': 'mf-geoadmin/python'}).status_code == 200:
<a href="${itf_url}" target="_blank">
ITF</a>
% else:
Expand Down
6 changes: 3 additions & 3 deletions chsdi/templates/htmlpopup/windatlas50.mako
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def getAltitude(baseUrl, center):
fullUrl = 'http:' + baseUrl +'/rest/services/height'
response = requests.get(
fullUrl + '?easting=%s&northing=%s&elevation_model=COMB' % (center[0], center[1]),
headers={'Referer': fullUrl})
headers={'Referer': fullUrl, 'User-Agent': 'mf-geoadmin/python'})
result = response.json()
return result['height']
%>
Expand All @@ -23,7 +23,7 @@ grid = Grid(gridSpec.get('extent'), gridSpec.get('resolutionX'), gridSpec.get('r
extent = grid.cellExtent(col,row)
center = [(extent[0] + extent[2])/2,(extent[1] + extent[3])/2]
baseUrl = request.registry.settings['api_url']
dhm_altitude = int(round(float(getAltitude(baseUrl, center)),0))
dhm_altitude = int(round(float(getAltitude(request.registry.settings['host'], center)),0))
center = '2%s, 1%s' % (str(int(round(center[0], 0))), str(int(round(center[1], 0))))
props = c['attributes']
Expand Down Expand Up @@ -75,7 +75,7 @@ bottomLeft = coordinates[0]
topRight = coordinates[2]
center = [(bottomLeft[0] + topRight[0]) / 2, (bottomLeft[1] + topRight[1]) / 2]
baseUrl = request.registry.settings['api_url']
dhm_altitude = int(round(float(getAltitude(baseUrl, center)),0))
dhm_altitude = int(round(float(getAltitude(request.registry.settings['host'], center)),0))
center = '2%s, 1%s' % (str(int(round(center[0], 0))), str(int(round(center[1], 0))))
altitude = int(c['layerBodId'].split('ch.bfe.windenergie-geschwindigkeit_h')[1])
Expand Down

0 comments on commit c08d2a3

Please sign in to comment.