-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_country.py
45 lines (37 loc) · 1.44 KB
/
get_country.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import json
import pandas as pd
import io
from geopy.geocoders import Nominatim
import requests
def get_country_name(latitude, longitude):
url = f"https://nominatim.openstreetmap.org/reverse?format=json&lat={latitude}&lon={longitude}"
response = requests.get(url)
data = response.json()
# print(response)
if 'address' in data:
if 'country' in data['address']:
country_name = data['address']['country']
# print(country_name)
return country_name
return None
with open("datasets\enriched_original_EOR-2023-04-30.json", encoding="utf-8") as f:
data = json.load(f)
i = 0
for feature in data['features']:
if feature['geometry'].get('coordinates'):
longitude, latitude = feature["geometry"]["coordinates"]
country = get_country_name(latitude, longitude)
if country == 'Україна':
i +=1
print(i)
print(i)
# with open("datasets/enriched_original_ukr-civharm-2023-04-30.json", encoding="utf-8") as f:
# data = json.load(f)
# i = 0
# for d in data:
# latitude = d['latitude']
# longitude = d['longitude']
# country = get_country_name(latitude, longitude)
# if country == 'Україна':
# i +=1
# print(i)