Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dependence removal #49

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ channels:
- defaults

dependencies:
- requests
- pillow
- pydantic
- httpx
Expand All @@ -20,7 +19,6 @@ dependencies:
- black
- flake8
- mypy
- types-requests
- types-Pillow
- build
- twine
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ def readme():
packages=["streetview"],
zip_safe=False,
install_requires=[
"requests",
"pillow",
"pydantic",
"httpx"
Expand Down
11 changes: 6 additions & 5 deletions streetview/api.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from io import BytesIO
from typing import Dict, Union

import requests
import httpx
from PIL import Image
from pydantic import BaseModel

Expand Down Expand Up @@ -31,7 +31,7 @@ def get_panorama_meta(pano_id: str, api_key: str) -> MetaData:
"https://maps.googleapis.com/maps/api/streetview/metadata"
f"?pano={pano_id}&key={api_key}"
)
resp = requests.get(url)
resp = httpx.get(url)
return MetaData(**resp.json())


Expand Down Expand Up @@ -73,6 +73,7 @@ def get_streetview(
"key": api_key,
}

response = requests.get(url, params=params, stream=True)
img = Image.open(BytesIO(response.content))
return img
with httpx.stream("GET", url, params=params) as response:
response.read()
img = Image.open(BytesIO(response.content))
return img
10 changes: 5 additions & 5 deletions streetview/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from typing import AsyncGenerator, Generator, Tuple

import httpx
import requests
from PIL import Image

async_client = httpx.AsyncClient()
Expand Down Expand Up @@ -56,12 +55,13 @@ def fetch_panorama_tile(
"""
for _ in range(max_retries):
try:
response = requests.get(tile_info.fileurl, stream=True)
return Image.open(BytesIO(response.content))
except requests.ConnectionError:
with httpx.stream("GET", tile_info.fileurl) as response:
response.read()
return Image.open(BytesIO(response.content))
except httpx.RequestError:
print("Connection error. Trying again in 2 seconds.")
time.sleep(2)
raise requests.ConnectionError("Max retries exceeded.")
raise httpx.RequestError("Max retries exceeded.")


async def fetch_panorama_tile_async(
Expand Down
9 changes: 4 additions & 5 deletions streetview/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
import re
from typing import List, Optional

import requests
import httpx
from pydantic import BaseModel
from requests.models import Response


class Panorama(BaseModel):
Expand Down Expand Up @@ -34,13 +33,13 @@ def make_search_url(lat: float, lon: float) -> str:
return url.format(lat, lon)


def search_request(lat: float, lon: float) -> Response:
def search_request(lat: float, lon: float) -> httpx.Response:
"""
Gets the response of the script on Google's servers that returns the
closest panoramas (ids) to a give GPS coordinate.
"""
url = make_search_url(lat, lon)
return requests.get(url)
return httpx.get(url)


def extract_panoramas(text: str) -> List[Panorama]:
Expand Down Expand Up @@ -83,7 +82,7 @@ def extract_panoramas(text: str) -> List[Panorama]:
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,
elevation=pano[3][0],
elevation=pano[3][0] if len(pano) >= 4 else None,
)
for i, pano in enumerate(raw_panos)
]
Expand Down