Skip to content

Commit

Permalink
hotfix and fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mvexel committed Apr 6, 2018
1 parent eef03b6 commit b77865a
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 23 deletions.
1 change: 1 addition & 0 deletions .pytest_cache/v/cache/lastfailed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
4 changes: 4 additions & 0 deletions .pytest_cache/v/cache/nodeids
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[
"tests/test_api.py::test_initialize_api",
"tests/test_api.py::test_geojson"
]
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Simplest example:
```python
import overpass
api = overpass.API()
response = api.Get('node["name"="Salt Lake City"]')
response = api.get('node["name"="Salt Lake City"]')
```

Note that you don't have to include any of the output meta statements.
Expand All @@ -37,7 +37,7 @@ print [(feature['tags']['name'], feature['id']) for feature in response['element
You can specify the format of the response. By default, you will get GeoJSON using the `responseformat` parameter. Alternatives are plain JSON (`json`) and OSM XML (`xml`), as ouput directly by the Overpass API.

```python
response = api.Get('node["name"="Salt Lake City"]', responseformat="xml")
response = api.get('node["name"="Salt Lake City"]', responseformat="xml")
```

### Parameters
Expand Down Expand Up @@ -81,8 +81,8 @@ query in a bounding box (the 'map call'). You just pass the bounding box
to the constructor:

```python
map_query = overpass.MapQuery(50.746,7.154,50.748,7.157)
response = api.Get(map_query)
MapQuery = overpass.MapQuery(50.746,7.154,50.748,7.157)
response = api.get(MapQuery)
```

#### WayQuery
Expand All @@ -92,8 +92,8 @@ satisfy certain criteria. Pass the criteria as a Overpass QL stub to the
constructor:

```python
way_query = overpass.WayQuery('[name="Highway 51"]')
response = api.Get(way_query)
WayQuery = overpass.WayQuery('[name="Highway 51"]')
response = api.get(WayQuery)
```

## Testing
Expand Down
16 changes: 8 additions & 8 deletions examples/turn_restriction_relations_as_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@

turn_restrictions_list = []

overpass_response = api.Get(
turn_restrictions_query,
responseformat='csv(::"id",::"user",::"timestamp",restriction,"restriction:conditional")',
verbosity='meta')
overpass_response = api.get(
turn_restrictions_query,
responseformat='csv(::"id",::"user",::"timestamp",restriction,"restriction:conditional")',
verbosity='meta')

print(overpass_response)
#reader = csv.reader(response)
#turn_restrictions_list = list(reader)
# reader = csv.reader(response)
# turn_restrictions_list = list(reader)

for row in overpass_response.split('\n'):
turn_restrictions_list.append([elem for elem in row.split('\t')])
turn_restrictions_list.append([elem for elem in row.split('\t')])

print(turn_restrictions_list)
print(turn_restrictions_list)
2 changes: 1 addition & 1 deletion overpass/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
from .errors import (
OverpassError, OverpassSyntaxError, TimeoutError, MultipleRequestsError, ServerLoadError, UnknownOverpassError
)
from .utils import *
from .utils import *
2 changes: 1 addition & 1 deletion overpass/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def get(self,
elif content_type == "text/xml" or content_type == "application/xml":
return r.text

response = json.loads(r)
response = json.loads(r.text)

# Check for valid answer from Overpass.
# A valid answer contains an 'elements' key at the root level.
Expand Down
7 changes: 4 additions & 3 deletions overpass/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class MapQuery(object):
def __init__(self, south, west, north, east):
"""
Initialize query with given bounding box.
:param bbox Bounding box with limit values in format west, south,
east, north.
"""
Expand All @@ -27,15 +28,15 @@ def __str__(self):


class WayQuery(object):
"""Query to retrieve a set of ways and their dependent nodes satisfying
the input parameters"""
"""Query to retrieve a set of ways and their dependent nodes satisfying the input parameters."""

_QUERY_TEMPLATE = "(way{query_parameters});(._;>;);"

def __init__(self, query_parameters):
"""Initialize a query for a set of ways satisfying the given parameters.
:param query_parameters Overpass QL query parameters"""
:param query_parameters Overpass QL query parameters
"""
self.query_parameters = query_parameters

def __str__(self):
Expand Down
12 changes: 8 additions & 4 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@ def test_initialize_api():


def test_geojson():
api = overpass.API()
api = overpass.API(debug=True)

osm_geo = api.Get(
overpass.MapQuery(37.86517, -122.31851, 37.86687, -122.31635))
MapQuery = overpass.MapQuery(37.86517, -122.31851, 37.86687, -122.31635)
print MapQuery
osm_geo = api.get(MapQuery)
print osm_geo
assert len(osm_geo['features']) > 1

osm_geo = api.Get('node(area:3602758138)[amenity=cafe]')
osm_geo = api.get('node(area:3602758138)[amenity=cafe]')
assert len(osm_geo['features']) > 1

test_geojson()

0 comments on commit b77865a

Please sign in to comment.