Skip to content
This repository was archived by the owner on Jun 1, 2022. It is now read-only.

Commit dfcaf8d

Browse files
committed
Made examples Python 3 compatible
1 parent 5e2329b commit dfcaf8d

File tree

8 files changed

+67
-52
lines changed

8 files changed

+67
-52
lines changed

examples/city.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
#!/usr/bin/python
22

3+
from __future__ import print_function
4+
35
import GeoIP
46

5-
gi = GeoIP.open("/usr/local/share/GeoIP/GeoIPCity.dat",GeoIP.GEOIP_STANDARD)
7+
gi = GeoIP.open("/usr/local/share/GeoIP/GeoIPCity.dat", GeoIP.GEOIP_STANDARD)
68

79
gir = gi.record_by_name("www.google.com")
810
#gir = gi.record_by_addr("24.24.24.24")
911

10-
if gir != None:
11-
print gir['country_code']
12-
print gir['country_code3']
13-
print gir['country_name']
14-
print gir['city']
15-
print gir['region']
16-
print gir['region_name']
17-
print gir['postal_code']
18-
print gir['latitude']
19-
print gir['longitude']
20-
print gir['area_code']
21-
print gir['time_zone']
22-
print gir['metro_code']
23-
print str(gir)
12+
if gir is not None:
13+
print(gir['country_code'])
14+
print(gir['country_code3'])
15+
print(gir['country_name'])
16+
print(gir['city'])
17+
print(gir['region'])
18+
print(gir['region_name'])
19+
print(gir['postal_code'])
20+
print(gir['latitude'])
21+
print(gir['longitude'])
22+
print(gir['area_code'])
23+
print(gir['time_zone'])
24+
print(gir['metro_code'])
25+
print(str(gir))

examples/country.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
#!/usr/bin/python
22

3+
from __future__ import print_function
4+
35
import GeoIP
46

57
#gi = GeoIP.new(GeoIP.GEOIP_STANDARD)
68
#gi = GeoIP.new(GeoIP.GEOIP_MMAP_CACHE)
79
gi = GeoIP.new(GeoIP.GEOIP_MEMORY_CACHE)
810
#gi = GeoIP.open("/usr/local/share/GeoIP/GeoIP.dat",GeoIP.GEOIP_STANDARD)
911

10-
print gi.country_code_by_name("yahoo.com")
11-
print gi.last_netmask()
12-
print gi.country_name_by_name("www.bundestag.de")
13-
print gi.country_code_by_addr("24.24.24.24")
14-
print gi.country_name_by_addr("24.24.24.24")
15-
print gi.range_by_ip("68.180.206.184")
16-
12+
print(gi.country_code_by_name("yahoo.com"))
13+
print(gi.last_netmask())
14+
print(gi.country_name_by_name("www.bundestag.de"))
15+
print(gi.country_code_by_addr("24.24.24.24"))
16+
print(gi.country_name_by_addr("24.24.24.24"))
17+
print(gi.range_by_ip("68.180.206.184"))

examples/domain.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#!/usr/bin/python
22

3+
from __future__ import print_function
4+
35
import GeoIP
46

5-
gi = GeoIP.open("/usr/local/share/GeoIP/GeoIPDomain.dat",GeoIP.GEOIP_STANDARD)
7+
gi = GeoIP.open("/usr/local/share/GeoIP/GeoIPDomain.dat", GeoIP.GEOIP_STANDARD)
68

7-
print gi.org_by_addr("24.24.24.24")
9+
print(gi.org_by_addr("24.24.24.24"))

examples/netspeed.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
#!/usr/bin/python
22

3+
from __future__ import print_function
4+
35
import GeoIP
46

5-
gi = GeoIP.open("/usr/local/share/GeoIP/GeoIPNetspeed.dat",GeoIP.GEOIP_STANDARD)
7+
gi = GeoIP.open(
8+
"/usr/local/share/GeoIP/GeoIPNetspeed.dat", GeoIP.GEOIP_STANDARD)
69

710
# GEOIP_UNKNOWN_SPEED, GEOIP_DIALUP_SPEED, GEOIP_CABLEDSL_SPEED or
811
# GEOIP_CORPORATE_SPEED
912

10-
print gi.id_by_name("yahoo.com")
11-
print gi.id_by_name("www.maxmind.com") == GeoIP.GEOIP_UNKNOWN_SPEED
12-
print gi.id_by_addr("203.195.93.0")
13+
print(gi.id_by_name("yahoo.com"))
14+
print(gi.id_by_name("www.maxmind.com") == GeoIP.GEOIP_UNKNOWN_SPEED)
15+
print(gi.id_by_addr("203.195.93.0"))

examples/netspeedcell.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
#!/usr/bin/python
22

3+
from __future__ import print_function
4+
35
import GeoIP
46

5-
gi = GeoIP.open("/usr/local/share/GeoIP/GeoIPNetSpeedCell.dat",GeoIP.GEOIP_STANDARD)
7+
gi = GeoIP.open(
8+
"/usr/local/share/GeoIP/GeoIPNetSpeedCell.dat", GeoIP.GEOIP_STANDARD)
69

7-
print gi.org_by_name("yahoo.com")
8-
print gi.org_by_name("www.google.com")
9-
print gi.org_by_addr("24.24.24.24")
10+
print(gi.org_by_name("yahoo.com"))
11+
print(gi.org_by_name("www.google.com"))
12+
print(gi.org_by_addr("24.24.24.24"))

examples/org.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
#!/usr/bin/python
22

3+
from __future__ import print_function
4+
35
import GeoIP
46

5-
gi = GeoIP.open("/usr/local/share/GeoIP/GeoIPOrg.dat",GeoIP.GEOIP_STANDARD)
7+
gi = GeoIP.open("/usr/local/share/GeoIP/GeoIPOrg.dat", GeoIP.GEOIP_STANDARD)
68

7-
print gi.org_by_name("yahoo.com")
8-
print gi.org_by_name("www.google.com")
9-
print gi.org_by_addr("24.24.24.24")
9+
print(gi.org_by_name("yahoo.com"))
10+
print(gi.org_by_name("www.google.com"))
11+
print(gi.org_by_addr("24.24.24.24"))

examples/region.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
#!/usr/bin/python
22

3+
from __future__ import print_function
4+
35
import GeoIP
46

5-
gi = GeoIP.open("/usr/local/share/GeoIP/GeoIPRegion.dat",GeoIP.GEOIP_STANDARD)
7+
gi = GeoIP.open("/usr/local/share/GeoIP/GeoIPRegion.dat", GeoIP.GEOIP_STANDARD)
68

79
gir = gi.region_by_name("www.google.com")
8-
if gir != None:
9-
print gir['country_code']
10+
if gir is not None:
11+
print(gir['country_code'])
1012

11-
print gir['region']
12-
print gir['region_name']
13+
print(gir['region'])
14+
print(gir['region_name'])
1315
gir = gi.region_by_addr("24.24.24.24")
14-
if gir != None:
15-
print gir['country_code']
16-
print gir['region']
17-
print gir['region_name']
18-
16+
if gir is not None:
17+
print(gir['country_code'])
18+
print(gir['region'])
19+
print(gir['region_name'])

examples/v6.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
#!/usr/bin/python
22

3+
from __future__ import print_function
4+
35
import GeoIP
46

57
#gi = GeoIP.new(GeoIP.GEOIP_STANDARD)
68
#gi = GeoIP.new(GeoIP.GEOIP_MEMORY_CACHE)
7-
gi = GeoIP.open("/usr/local/share/GeoIP/GeoIPv6.dat",GeoIP.GEOIP_STANDARD)
8-
9-
print gi.country_code_by_name_v6("ipv6.google.com")
10-
print gi.country_name_by_name_v6("ipv6.google.com")
11-
print gi.country_code_by_addr_v6("2001:4860:0:1001::68")
12-
print gi.country_name_by_addr_v6("2001:4860:0:1001::68")
9+
gi = GeoIP.open("/usr/local/share/GeoIP/GeoIPv6.dat", GeoIP.GEOIP_STANDARD)
1310

11+
print(gi.country_code_by_name_v6("ipv6.google.com"))
12+
print(gi.country_name_by_name_v6("ipv6.google.com"))
13+
print(gi.country_code_by_addr_v6("2001:4860:0:1001::68"))
14+
print(gi.country_name_by_addr_v6("2001:4860:0:1001::68"))

0 commit comments

Comments
 (0)