Added building_id fetcher

This commit is contained in:
Dmitriy Shishkov 2023-09-19 05:16:39 +03:00
parent 2c141250c9
commit 8a00fe48c5
Signed by: dm1sh
GPG Key ID: 027994B0AA357688
2 changed files with 26 additions and 1 deletions

View File

@ -1,2 +1,3 @@
from .rosseti import RossetiParser
from .address import split_addresses
from .address import split_addresses
from .building_id import fetch_builing_ids

24
parser/building_id.py Normal file
View File

@ -0,0 +1,24 @@
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