-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
|
||
import sys | ||
import argparse | ||
import pprint | ||
|
||
import ipapi | ||
|
||
|
||
|
||
def main(argv=None): | ||
argv = argv or sys.argv[1:] | ||
|
||
parser = argparse.ArgumentParser(description='IP Address Location & Geolocation API : https://ipapi.co/ by Kloudend, Inc.') | ||
|
||
parser.add_argument('-i', '--ip', dest='ip', help='IP Address (IPv4 or IPv6) that you wish to locate.'\ | ||
' If omitted, it defaults to the your machine\'s IP') | ||
parser.add_argument('-k', '--key', dest='key', help='API key (for paid plans). Omit it for free plan') | ||
parser.add_argument('-o', '--output', dest='output', help='Output format i.e. either json|csv|xml|yaml or '\ | ||
'Specific location field i.e. city|region|country etc. '\ | ||
'See https://ipapi.co/api for field details') | ||
|
||
args = parser.parse_args(argv) | ||
|
||
pprint.pprint(ipapi.location(args.ip, args.key, args.output), indent=4) | ||
|
||
|
||
if __name__ == "__main__": | ||
sys.exit(main()) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
|
||
''' exception classes used by ipapi package ''' | ||
|
||
class RateLimited(Exception): | ||
''' Request was rate limited : HTTP 429 ''' | ||
pass | ||
|
||
|
||
class AuthorizationFailed(Exception): | ||
''' Invalid authorization credentials : HTTP 403 ''' | ||
pass | ||
|
||
class PageNotFound(Exception): | ||
''' Page not found error : HTTP 404 ''' | ||
pass |