Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
ipapi-co authored Jul 26, 2020
1 parent 4d113d8 commit fe67533
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
29 changes: 29 additions & 0 deletions ipapi/__main__.py
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())

15 changes: 15 additions & 0 deletions ipapi/exceptions.py
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

0 comments on commit fe67533

Please sign in to comment.