|
3 | 3 | import json
|
4 | 4 | from datetime import date
|
5 | 5 |
|
| 6 | +import geoip2.database |
| 7 | +from geopy.geocoders import Nominatim |
| 8 | +import folium |
| 9 | +import math |
| 10 | +import urllib.request |
| 11 | + |
| 12 | +"""print(c.get_country_cities(country_code_iso="DE"))""" |
| 13 | +""" |
| 14 | +Geopy: input: University #correct some data (do later) Output: Address, lat, lon |
| 15 | +folium or Ivan's |
| 16 | +Must choose module to make the map |
| 17 | +""" |
| 18 | + |
| 19 | +def __get_affiliations(df): |
| 20 | + return df['affiliation'].value_counts().keys() |
| 21 | + |
| 22 | +def __get_coordin(university): |
| 23 | + geolocator = Nominatim(user_agent="my_geocoding_app") |
| 24 | + try: |
| 25 | + location = geolocator.geocode(university) |
| 26 | + if location: |
| 27 | + return location.latitude, location.longitude |
| 28 | + else: |
| 29 | + return (0,0) |
| 30 | + except: |
| 31 | + print(f"Geocoding service is unavailable for {university}") |
| 32 | + return 0, 0 |
| 33 | + |
| 34 | +def get_zero_coords(affiliation_coordinates): |
| 35 | + total = 0 |
| 36 | + zeros = 0 |
| 37 | + for university in affiliation_coordinates: |
| 38 | + if affiliation_coordinates[university] == (0 ,0): |
| 39 | + zeros +=1 |
| 40 | + print(affiliation_coordinates[university],university,"ain't working") |
| 41 | + total += 1 |
| 42 | + return zeros, total, math.ceil(zeros/total*100)/100 |
| 43 | + |
| 44 | +def __get_affilation_coordinates(df): |
| 45 | + affiliations_dict = {} |
| 46 | + for university in __get_affiliations(df): |
| 47 | + latitude, longitude = __get_coordin(university) |
| 48 | + if latitude is not None and longitude is not None: |
| 49 | + affiliations_dict[university] = (latitude, longitude) |
| 50 | + return affiliations_dict |
| 51 | + |
| 52 | +if __name__ == "__main__": |
| 53 | + affiliation_coordinates = __get_affilation_coordinates(df) |
| 54 | + print(affiliation_coordinates) |
| 55 | + print(get_zero_coords(affiliation_coordinates)) |
| 56 | + |
6 | 57 |
|
7 | 58 | def today():
|
8 | 59 | """
|
|
0 commit comments