iac_test/parser/building_id.py
2023-09-19 05:16:39 +03:00

25 lines
574 B
Python

from typing import Optional, Tuple
import requests
import pandas as pd
def get_building_id(row) -> Optional[Tuple[int, float, float]]:
r = requests.get('https://geocode.gate.petersburg.ru/parse/eas', params={
'street': row['Улица']
})
res = r.json()
if 'error' not in res:
return (res['Building_ID'], res['Longitude'], res['Latitude'])
return None
def fetch_builing_ids(df: pd.DataFrame) -> pd.DataFrame:
df[['Building_ID', 'lng', 'lat']] = df.apply(
get_building_id, axis=1, result_type='expand')
return df