first commit

main
José María Ávila 2 years ago
commit 390a8ba2d3

@ -0,0 +1,63 @@
# DOMAPI - Domain API, basic management
DOMAPI is a quick and simple API to get properties of a domain name.
## Key features
* Purely Python
* It's an API with 5 endpoints
* Needs flask library
* Needs wordsegment library
* Needs python-whois library
* Needs tldextract library
## Requirements
DOMAPI requires install next Python libraries with pip:
* pip install flask
* pip install wordsegment
* pip install python-whois
* pip install tldextract
## Usage
- Run: python .\wodapi.py
- Then, a server is deploy on http://127.0.0.1:5000
- Use GET with endpoints
- An error will occur if your parameter is not a well-formed domain.
## Endpoints
- words :: split a domain name in words. Only in English languaje, next versions will be available in other languages. Example: http://127.0.0.1:5000/words/hereyourdomainname.com
- whois :: return full whois info from domain. It works with many extensions, although some have limitations in use, such as the .NET extension. Example: http://127.0.0.1:5000/whois/hereyourdomainname.com
- tld :: return TLD or ccTLD or a domain. Example: http://127.0.0.1:5000/tld/hereyourdomainname.com
- domain :: return only domain of a full domain. Example: http://127.0.0.1:5000/domain/hereyourdomainname.com
- size :: returns the size of a domain, not counting its extension. Example: http://127.0.0.1:5000/size/hereyourdomainname.com
## TO-DO
- words in Italian and Spanish
- test if a domain is IDN
- conver between ascii-punycode-idn
## Documentation
This is the README file
## Authors
* Bichi - José Mª Ávila
* Antonio Villamarin
## License
This is a NIDOMA development
## Links
- https://grantjenks.com/docs/wordsegment/
- https://pypi.org/project/wordsegment/
- https://blog.stoplight.io/python-rest-api
- https://github.com/richardpenman/whois
- https://pypi.org/project/tldextract/

@ -0,0 +1,78 @@
import wordsegment
import re
import tldextract
from wordsegment import load, segment
from flask import Flask, json
load()
api = Flask(__name__)
NOTVALIDDOMAIN={"error":{"code":400,"message":"Bad Request. Not valid domain."}}
def is_domain(value: str):
pattern = re.compile(
r'^(([a-zA-Z]{1})|([a-zA-Z]{1}[a-zA-Z]{1})|'
r'([a-zA-Z]{1}[0-9]{1})|([0-9]{1}[a-zA-Z]{1})|'
r'([a-zA-Z0-9][-_.a-zA-Z0-9]{0,61}[a-zA-Z0-9]))\.'
r'([a-zA-Z]{2,13}|[a-zA-Z0-9-]{2,30}.[a-zA-Z]{2,3})$'
)
"""
Return whether or not given value is a valid domain.
If the value is valid domain name this function returns ``True``
:param value: domain string to validate
"""
return pattern.match(value)
def get_domain(value: str):
if(is_domain(value)):
ext = tldextract.extract(value)
return ext.domain
@api.route('/words/<string:name>', methods=['GET'])
def get_words(name: str):
if(is_domain(name)):
data = {}
data['words'] = segment(get_domain(name))
return json.dumps(data)
else:
return json.dumps(NOTVALIDDOMAIN)
@api.route('/whois/<string:name>', methods=['GET'])
def get_whois(name: str):
if(is_domain(name)):
import whois
who_var = whois.whois(name)
return json.dumps(who_var)
else:
return json.dumps(NOTVALIDDOMAIN)
@api.route('/tld/<string:name>', methods=['GET'])
def get_tld(name: str):
if(is_domain(name)):
ext = tldextract.extract(name)
data = {}
data['tld'] = ext.suffix
return json.dumps(data)
else:
return json.dumps(NOTVALIDDOMAIN)
@api.route('/domain/<string:name>', methods=['GET'])
def get_onlydomain(name: str):
if(is_domain(name)):
data = {}
data['domain'] = get_domain(name)
return json.dumps(data)
else:
return json.dumps(NOTVALIDDOMAIN)
@api.route('/size/<string:name>', methods=['GET'])
def get_size(name: str):
if(is_domain(name)):
data = {}
data['size'] = len(get_domain(name))
return json.dumps(data)
else:
return json.dumps(NOTVALIDDOMAIN)
if __name__ == '__main__':
api.run()
Loading…
Cancel
Save