Skip to content

Commit fe67533

Browse files
authored
Add files via upload
1 parent 4d113d8 commit fe67533

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

ipapi/__main__.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
import sys
3+
import argparse
4+
import pprint
5+
6+
import ipapi
7+
8+
9+
10+
def main(argv=None):
11+
argv = argv or sys.argv[1:]
12+
13+
parser = argparse.ArgumentParser(description='IP Address Location & Geolocation API : https://ipapi.co/ by Kloudend, Inc.')
14+
15+
parser.add_argument('-i', '--ip', dest='ip', help='IP Address (IPv4 or IPv6) that you wish to locate.'\
16+
' If omitted, it defaults to the your machine\'s IP')
17+
parser.add_argument('-k', '--key', dest='key', help='API key (for paid plans). Omit it for free plan')
18+
parser.add_argument('-o', '--output', dest='output', help='Output format i.e. either json|csv|xml|yaml or '\
19+
'Specific location field i.e. city|region|country etc. '\
20+
'See https://ipapi.co/api for field details')
21+
22+
args = parser.parse_args(argv)
23+
24+
pprint.pprint(ipapi.location(args.ip, args.key, args.output), indent=4)
25+
26+
27+
if __name__ == "__main__":
28+
sys.exit(main())
29+

ipapi/exceptions.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
''' exception classes used by ipapi package '''
3+
4+
class RateLimited(Exception):
5+
''' Request was rate limited : HTTP 429 '''
6+
pass
7+
8+
9+
class AuthorizationFailed(Exception):
10+
''' Invalid authorization credentials : HTTP 403 '''
11+
pass
12+
13+
class PageNotFound(Exception):
14+
''' Page not found error : HTTP 404 '''
15+
pass

0 commit comments

Comments
 (0)