Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
#This module was written by Humza Shahid.
import pygeoip
from requests import get
def userLocator():
"""Gets user's city and country from their IP address, and then returns the city and country"""
#note: database uses different files for finding user's city and country
#note: (GeoIP.dat is for countries and GeoLiteCity.dat is for cities)
#note: so two different files and variables are needed to get required info.
gi = pygeoip.GeoIP('GeoIP.dat')
gic = pygeoip.GeoIP('GeoLiteCity.dat')
ip = get('https://api.ipify.org').text
userCity = gic.record_by_addr(ip)['city']
userCountry = gi.country_name_by_addr(ip)
return userCity, userCountry