Skip to content

Instantly share code, notes, and snippets.

@cstayyab
Last active April 11, 2020 09:35
Show Gist options
  • Save cstayyab/83e5ccaa4c5ee9c2b5454182ea67804e to your computer and use it in GitHub Desktop.
Save cstayyab/83e5ccaa4c5ee9c2b5454182ea67804e to your computer and use it in GitHub Desktop.
83e5ccaa4c5ee9c2b5454182ea67804e#file-libravatar-demo-ipynb
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"colab": {
"name": "83e5ccaa4c5ee9c2b5454182ea67804e#file-libravatar-demo-ipynb",
"provenance": [],
"collapsed_sections": [],
"include_colab_link": true
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/gist/cstayyab/83e5ccaa4c5ee9c2b5454182ea67804e/libravatar-demo.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "code",
"metadata": {
"id": "C1dxslKthsq4",
"colab_type": "code",
"outputId": "49c33b70-5614-4300-b993-ac42b9f308c8",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 124
}
},
"source": [
"# Install dnspython module\n",
"!pip3 install dnspython"
],
"execution_count": 0,
"outputs": [
{
"output_type": "stream",
"text": [
"Collecting dnspython\n",
"\u001b[?25l Downloading https://files.pythonhosted.org/packages/ec/d3/3aa0e7213ef72b8585747aa0e271a9523e713813b9a20177ebe1e939deb0/dnspython-1.16.0-py2.py3-none-any.whl (188kB)\n",
"\u001b[K |████████████████████████████████| 194kB 2.5MB/s \n",
"\u001b[?25hInstalling collected packages: dnspython\n",
"Successfully installed dnspython-1.16.0\n"
],
"name": "stdout"
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "6B71kCgZhdqv",
"colab_type": "code",
"outputId": "c8bd9c90-a78e-4a45-af55-5ffbb092640a",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 34
}
},
"source": [
"import dns.resolver\n",
"import hashlib\n",
"email = '[email protected]'.encode('utf-8') # Enter a proper email address\n",
"_, domain = email.split(b'@')\n",
"try:\n",
" answers = dns.resolver.query('_avatars._tcp.' + domain, 'SRV')\n",
" baseurl = 'http://' + str(answers[0].target) + '/avatar/'\n",
"except:\n",
" baseurl = \"http://cdn.libravatar.org/avatar/\"\n",
"hash = hashlib.md5(email.strip().lower()).hexdigest()\n",
"print(baseurl + hash + \"?s=512&d=identicon\")"
],
"execution_count": 0,
"outputs": [
{
"output_type": "stream",
"text": [
"http://cdn.libravatar.org/avatar/ce41e057abd4a0b197072e568df1786d?s=512&d=identicon\n"
],
"name": "stdout"
}
]
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment