forked from JetBrains/kotlin-web-site
-
Notifications
You must be signed in to change notification settings - Fork 0
/
user_groups_geolocator.py
44 lines (31 loc) · 1.48 KB
/
user_groups_geolocator.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
from os import path
import geocoder
from ruamel import yaml
data_folder = path.join(path.dirname(__file__), "../data")
data_file = path.join(data_folder, "user-groups.yml")
with open(data_file, encoding="utf-8") as points_file:
sections = yaml.load(points_file, yaml.RoundTripLoader)
for n, section in enumerate(sections):
for n, user_group in enumerate(section['groups']):
city = user_group.get("name").replace("Kotlin", "").replace("User", "").replace("Group", "").strip()
location = city + ", " + user_group.get("country")
if 'position' in user_group or 'isVirtual' in user_group and user_group['isVirtual']:
print(location + " (saved previous)")
continue
print("Process %s..." % location)
response = geocoder.google(location)
coordinates = response.latlng
if coordinates is None or len(coordinates) == 0:
raise Exception("Location not found: " + location)
if response.ok is not True:
raise Exception("Location not resolved: ", location)
new_geo = {
"lat": coordinates[0],
"lng": coordinates[1],
}
print("Will coordinates for \"%s\":\nhttps://www.google.com/maps/search/?api=1&query=%s,%s""" % (
location, new_geo['lat'], new_geo['lng']
))
user_group['position'] = new_geo
with open(data_file, 'w') as points_file:
yaml.dump(sections, stream=points_file, Dumper=yaml.RoundTripDumper, allow_unicode=True)