Skip to content

Instantly share code, notes, and snippets.

@xunleii
Last active April 25, 2021 20:00
Show Gist options
  • Save xunleii/be3d1971ea9dac5c30d598dbd88b44ac to your computer and use it in GitHub Desktop.
Save xunleii/be3d1971ea9dac5c30d598dbd88b44ac to your computer and use it in GitHub Desktop.
'English word'ed domain resolver' Notebook for Jupyter

'English word'ed domain resolver' Notebook for Jupyter

The goal of this notebook is to easily find an available domain based on the English dictionary.

This Notebook can be launched directly from mybinder.org

Display the source blob
Display the rendered blob
Raw
{
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.8"
}
},
"nbformat_minor": 5,
"nbformat": 4,
"cells": [
{
"cell_type": "markdown",
"source": "# English word'ed domain resolver\n\n*The goal of this notebook is to easily find an available domain based on the English dictionary.*\n\n---\n\n## Prerequisite (prepare environment)",
"metadata": {}
},
{
"cell_type": "code",
"source": "from __future__ import print_function\nimport sys",
"metadata": {
"trusted": true
},
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"source": "from ipywidgets import interact, interactive, fixed, interact_manual\nimport ipywidgets as widgets\nimport pandas\nimport whois",
"metadata": {
"trusted": true
},
"execution_count": 0,
"outputs": []
},
{
"cell_type": "markdown",
"source": "## Setup dictionnary and domain list",
"metadata": {}
},
{
"cell_type": "code",
"source": "english_dict_url = 'https://github.com/dwyl/english-words/raw/master/words_alpha.txt'\n#domain_list_url = 'https://pkgstore.datahub.io/core/top-level-domain-names/top-level-domain-names.csv_csv/data/667f4464088f3ca10522e0e2e39c8ae4/top-level-domain-names.csv_csv.csv'",
"metadata": {
"trusted": true
},
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"source": "en_dict = pandas.read_csv(english_dict_url,names=[\"Word\"]).dropna(subset=[\"Word\"])\n\ndomains = pandas.DataFrame({'Domain': ['.{}'.format(d.replace('_', '.').rstrip('.')) for d in whois.TLD_RE.keys()]})\n#domains = pandas.read_csv(domain_list_url).drop(labels=[\"Type\",\"Sponsoring Organisation\"], axis=1)\n#domains = domains[domains.apply(lambda d: all(ord(c) < 128 for c in d.Domain), axis=1)]",
"metadata": {
"trusted": true
},
"execution_count": 0,
"outputs": []
},
{
"cell_type": "markdown",
"source": "---\n## Run UI",
"metadata": {}
},
{
"cell_type": "code",
"source": "def selector(x):\n words = en_dict[en_dict.Word.str.contains(x)]\n if words.size > 10000:\n return 'Too much words found ({})'.format(words.size)\n results = {word: [(word[::-1].replace(d.replace('.','')[::-1],d[::-1], 1))[::-1] for d in domains.Domain if word.endswith(d.replace('.',''))] for word in words.Word}\n results = {k: results[k] for k in results.keys() if results[k]}\n return results\n\ninteract(selector, x=widgets.Text(description=' '));",
"metadata": {
"trusted": true
},
"execution_count": 0,
"outputs": []
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment