Skip to content

Commit

Permalink
Fix error on missing pitch and roll (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
robolyst authored Jul 23, 2023
1 parent f43a091 commit 5b4947c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
12 changes: 8 additions & 4 deletions streetview/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import time
from dataclasses import dataclass
from io import BytesIO
from typing import Generator
from typing import Generator, Tuple

import requests
from PIL import Image
Expand All @@ -22,9 +22,10 @@ class Tile:
image: Image.Image


def get_width_and_height_from_zoom(zoom: int) -> (int, int):
def get_width_and_height_from_zoom(zoom: int) -> Tuple[int, int]:
"""
Returns the width and height of a panorama at a given zoom level, depends on the zoom level.
Returns the width and height of a panorama at a given zoom level, depends on the
zoom level.
"""
return 2**zoom, 2 ** (zoom - 1)

Expand All @@ -33,7 +34,10 @@ def make_download_url(pano_id: str, zoom: int, x: int, y: int) -> str:
"""
Returns the URL to download a tile.
"""
return f"https://cbk0.google.com/cbk?output=tile&panoid={pano_id}&zoom={zoom}&x={x}&y={y}"
return (
"https://cbk0.google.com/cbk"
f"?output=tile&panoid={pano_id}&zoom={zoom}&x={x}&y={y}"
)


def fetch_panorama_tile(tile_info: TileInfo) -> Image.Image:
Expand Down
8 changes: 4 additions & 4 deletions streetview/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class Panorama(BaseModel):
lat: float
lon: float
heading: float
pitch: float
roll: float
pitch: Optional[float]
roll: Optional[float]
date: Optional[str]


Expand Down Expand Up @@ -79,8 +79,8 @@ def extract_panoramas(text: str) -> List[Panorama]:
lat=pano[2][0][2],
lon=pano[2][0][3],
heading=pano[2][2][0],
pitch=pano[2][2][1],
roll=pano[2][2][2],
pitch=pano[2][2][1] if len(pano[2][2]) >= 2 else None,
roll=pano[2][2][2] if len(pano[2][2]) >= 3 else None,
date=dates[i] if i < len(dates) else None,
)
for i, pano in enumerate(raw_panos)
Expand Down
12 changes: 12 additions & 0 deletions tests/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,15 @@ def test_search_where_there_are_no_dates():

dates = [p.date for p in result]
assert dates == [None] * len(dates)


def test_coordinates_with_missing_pitch():
panos = search_panoramas(35.658353457849685, 139.6920989241623)
is_pitch_none = [p.pitch is None for p in panos]
assert any(is_pitch_none)


def test_coordinates_with_missing_roll():
panos = search_panoramas(35.658353457849685, 139.6920989241623)
is_roll_none = [p.roll is None for p in panos]
assert any(is_roll_none)

0 comments on commit 5b4947c

Please sign in to comment.