Skip to content

Instantly share code, notes, and snippets.

@liketaurus
Last active December 21, 2023 10:31
Show Gist options
  • Save liketaurus/23674e8c5469e64929e7aea63d40bec4 to your computer and use it in GitHub Desktop.
Save liketaurus/23674e8c5469e64929e7aea63d40bec4 to your computer and use it in GitHub Desktop.
A very simple URL-shortener and QR-code generator
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/gist/liketaurus/23674e8c5469e64929e7aea63d40bec4/scratchpad.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "code",
"source": [
"!pip install pillow\n",
"!pip install qrcode\n",
"\n",
"import requests\n",
"import qrcode\n",
" \n",
"# api-endpoint\n",
"URL = \"https://is.gd/create.php?format=json&url=\"\n",
"\n",
"site = input(\"Enter URL to shorten:\")\n",
"\n",
"URL=URL+site\n",
" \n",
"# sending get request and saving the response as response object\n",
"r = requests.get(URL) \n",
"# extracting data\n",
"shortURL = r.json()[\"shorturl\"]\n",
"\n",
"print (\"Your URL is now accessible as \"+ shortURL)\n",
"\n",
"qr = qrcode.QRCode(\n",
" version=1,\n",
" box_size=10,\n",
" border=5)\n",
"qr.add_data(shortURL)\n",
"qr.make(fit=True)\n",
"img = qr.make_image(fill='black', back_color='white')\n",
"# img.save('qrcode001.png')\n",
"print(\"Here is also QR-code for this URL:\")\n",
"img"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 656
},
"id": "2KqRfjFyxlgp",
"outputId": "03290c02-8a5e-4835-a537-51c998b12b77"
},
"execution_count": 2,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Requirement already satisfied: pillow in /usr/local/lib/python3.7/dist-packages (7.1.2)\n",
"Collecting qrcode\n",
" Downloading qrcode-7.3.1.tar.gz (43 kB)\n",
"\u001b[K |████████████████████████████████| 43 kB 1.6 MB/s \n",
"\u001b[?25hBuilding wheels for collected packages: qrcode\n",
" Building wheel for qrcode (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
" Created wheel for qrcode: filename=qrcode-7.3.1-py3-none-any.whl size=40402 sha256=d9fe3eaac1a74bc15f8a282d156f79ee03cedbde41db67ebca9c89a319f7cfa1\n",
" Stored in directory: /root/.cache/pip/wheels/93/d7/39/a4111be2cfb8e679938aa671a37888b6afb1f9e7d748e94492\n",
"Successfully built qrcode\n",
"Installing collected packages: qrcode\n",
"Successfully installed qrcode-7.3.1\n",
"Enter URL to shorten:www.google.com\n",
"Your URL is now accessible as https://is.gd/WzFWtC\n",
"Here is also QR-code for this URL:\n"
]
},
{
"output_type": "execute_result",
"data": {
"text/plain": [
"<qrcode.image.pil.PilImage at 0x7f57dbc64490>"
],
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAV4AAAFeAQAAAADlUEq3AAAB+ElEQVR4nO2bTYrjMBBGX40Ms1SgD9BHUY4eH6UPMGAvGyS+WViW7SQw6TDp0UDVQkjWW3xQSPUjbOJhKz8eZ8Fhhx122GGHHXb41TCSJF225QSkKYikvH6NkqTciWaHD1Y9WH2ELlFaN/LVbieaHb4LFzM7AcwDEDOMJ2A0s++U4fBfgIvB/PNendivZoc3S8qQ9Gl2/pcyHH7UhnUSBJRlZgCCAml/FjvR7PDBrnPRS8y7oZpnMv3C1YObXQCSJNL1lnuwR/hONdEGWnnoHuwXrnEwfRhAkKWP+snS9JbtAHei2eGDXcVB0gTSFLQUhWmZ+RnsFm5xsHmLUJcQpAvBezJdw7szWIcorc1Ragh0D3YMD9u0Br5YBo3nkBnfhdWNV8tw+Gm45aK5hcA1A61VvsfBvuF9NVGfJcKhKJzazeoe7BLen0Fiy1/WehBi3pKdTjQ7fLCbnkw8zLale7BreLRqpKnY+ipYakE/nr5JhsNfh9dcNE4AZVlaUhmomcy3yHD4abhVE2WA+AuY32T1icmAWAaIr5bh8NPwcPupmEYLWeMZBKg1RzvR7PAf4KAlGCZJMJu1rmm/mh1euqETQPw0xlNQzW7epVv4dTIc/iq83qLzelWO5yX+UbObeWgv9b1odnhv5v8uOeywww477LDD/y38G1+EpW97X7OnAAAAAElFTkSuQmCC\n"
},
"metadata": {},
"execution_count": 2
}
]
}
],
"metadata": {
"colab": {
"name": "scratchpad",
"provenance": [],
"include_colab_link": true
},
"kernelspec": {
"display_name": "Python 3",
"name": "python3"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment