diff --git a/Copy_of_Mudasarinfrac.ipynb b/Copy_of_Mudasarinfrac.ipynb new file mode 100644 index 0000000000..9db933e882 --- /dev/null +++ b/Copy_of_Mudasarinfrac.ipynb @@ -0,0 +1,568 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "provenance": [], + "authorship_tag": "ABX9TyNvBXHoZW71MHcuumzXAp+z", + "include_colab_link": true + }, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + }, + "language_info": { + "name": "python" + } + }, + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "view-in-github", + "colab_type": "text" + }, + "source": [ + "\"Open" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "65lHeRTBMCBt", + "outputId": "920c903f-2c58-4784-b253-d8f15ec5310c" + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/\n", + "Collecting pyshorteners\n", + " Downloading pyshorteners-1.0.1.tar.gz (10.0 kB)\n", + " Preparing metadata (setup.py) ... \u001b[?25l\u001b[?25hdone\n", + "Requirement already satisfied: requests in /usr/local/lib/python3.10/dist-packages (from pyshorteners) (2.27.1)\n", + "Requirement already satisfied: urllib3<1.27,>=1.21.1 in /usr/local/lib/python3.10/dist-packages (from requests->pyshorteners) (1.26.15)\n", + "Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.10/dist-packages (from requests->pyshorteners) (2022.12.7)\n", + "Requirement already satisfied: charset-normalizer~=2.0.0 in /usr/local/lib/python3.10/dist-packages (from requests->pyshorteners) (2.0.12)\n", + "Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.10/dist-packages (from requests->pyshorteners) (3.4)\n", + "Building wheels for collected packages: pyshorteners\n", + " Building wheel for pyshorteners (setup.py) ... \u001b[?25l\u001b[?25hdone\n", + " Created wheel for pyshorteners: filename=pyshorteners-1.0.1-py3-none-any.whl size=17479 sha256=afe94b3bc7dc3f7e592db1b9208bf58a98b1e709af4ec395a2459e01b7ac994e\n", + " Stored in directory: /root/.cache/pip/wheels/d5/ff/b3/16d8906f92ab0b042f76a4696fcea11d291d79a2b3a3de1e78\n", + "Successfully built pyshorteners\n", + "Installing collected packages: pyshorteners\n", + "Successfully installed pyshorteners-1.0.1\n" + ] + } + ], + "source": [ + "pip install pyshorteners" + ] + }, + { + "cell_type": "code", + "source": [ + "import pyshorteners\n", + "\n", + "def shorten_url(url):\n", + " s = pyshorteners.Shortener()\n", + " shortened_url = s.tinyurl.short(url)\n", + " return shortened_url\n", + "\n", + "# Example usage\n", + "long_url = \"https://www.youtube.com/watch?v=E6GPMTDx41Y\"\n", + "short_url = shorten_url(long_url)\n", + "print(\"Short URL:\", short_url)" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "e3Pg6XaLMfAg", + "outputId": "a185e7c9-524a-4285-a59b-efae85ce732e" + }, + "execution_count": null, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Short URL: https://tinyurl.com/2g47dx37\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "import pyshorteners\n", + "\n", + "def shorten_url(url):\n", + " s = pyshorteners.Shortener()\n", + " shortened_url = s.tinyurl.short(url)\n", + " return shortened_url\n", + "\n", + "# Example usage\n", + "long_url = \"https://www.youtube.com/watch?v=U8_YEWuBybI\"\n", + "short_url = shorten_url(long_url)\n", + "print(\"Short URL:\", short_url)" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "-_cshk2dNq-r", + "outputId": "3f3f429f-27a6-44b2-fcfb-a2a7ffa2ab75" + }, + "execution_count": null, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Short URL: https://tinyurl.com/2h4vcxuk\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "import pyshorteners\n", + "\n", + "def shorten_url(url):\n", + " s = pyshorteners.Shortener()\n", + " shortened_url = s.tinyurl.short(url)\n", + " return shortened_url\n", + "\n", + "# Example usage\n", + "long_url = \"https://www.youtube.com/watch?v=ZSiXZxVpVhs\"\n", + "short_url = shorten_url(long_url)\n", + "print(\"Short URL:\", short_url)" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "dHNc7GWMOi2S", + "outputId": "81e8f8f2-1445-43e7-d510-245c2131a0fd" + }, + "execution_count": null, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Short URL: https://tinyurl.com/2r2pcw4c\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "import pyshorteners\n", + "\n", + "def shorten_url(url):\n", + " s = pyshorteners.Shortener()\n", + " shortened_url = s.tinyurl.short(url)\n", + " return shortened_url\n", + "\n", + "# Example usage\n", + "long_url = \"https://www.youtube.com/watch?v=vYCjjAz3UD0\"\n", + "short_url = shorten_url(long_url)\n", + "print(\"Short URL:\", short_url)" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "gbEFz6OCOvZO", + "outputId": "180287e0-fc17-4e7d-90c3-60b9bf4a9385" + }, + "execution_count": null, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Short URL: https://tinyurl.com/2fzbn924\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "import pyshorteners\n", + "\n", + "def shorten_url(url):\n", + " s = pyshorteners.Shortener()\n", + " shortened_url = s.tinyurl.short(url)\n", + " return shortened_url\n", + "\n", + "# Example usage\n", + "long_url = \"https://stackoverflow.blog/2021/12/30/how-often-do-people-actually-copy-and-paste-from-stack-overflow-now-we-know/\"\n", + "short_url = shorten_url(long_url)\n", + "print(\"Short URL:\", short_url)" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "YfHDQiwHO8Ob", + "outputId": "23074cb2-6e2d-4b89-bbef-a2e5a0d06dd9" + }, + "execution_count": null, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Short URL: https://tinyurl.com/2knnnyae\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "import pyshorteners\n", + "\n", + "def shorten_url(url):\n", + " s = pyshorteners.Shortener()\n", + " shortened_url = s.tinyurl.short(url)\n", + " return shortened_url\n", + "\n", + "# Example usage\n", + "long_url = \"https://en.wikipedia.org/wiki/Artificial_Intelligence_Markup_Language\"\n", + "short_url = shorten_url(long_url)\n", + "print(\"Short URL:\", short_url)" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "I9Z3VsP6PFFw", + "outputId": "cc574317-ed7c-4b6b-a402-722b2bba801f" + }, + "execution_count": null, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Short URL: https://tinyurl.com/2occ6bkt\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "import pyshorteners\n", + "\n", + "def shorten_url(url):\n", + " s = pyshorteners.Shortener()\n", + " shortened_url = s.tinyurl.short(url)\n", + " return shortened_url\n", + "\n", + "# Example usage\n", + "long_url = \"https://en.wikipedia.org/wiki/Artificial_Linguistic_Internet_Computer_Entity\"\n", + "short_url = shorten_url(long_url)\n", + "print(\"Short URL:\", short_url)" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "OKIstCCnPNqz", + "outputId": "e9348b71-6ec0-45b4-efd8-e4e7deb6e78e" + }, + "execution_count": null, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Short URL: https://tinyurl.com/cdgsybc\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "import pyshorteners\n", + "\n", + "def shorten_url(url):\n", + " s = pyshorteners.Shortener()\n", + " shortened_url = s.tinyurl.short(url)\n", + " return shortened_url\n", + "\n", + "# Example usage\n", + "long_url = \"https://www.udemy.com/?ranMID=39197&ranEAID=yNfEamYSgXk&ranSiteID=yNfEamYSgXk-FaJv9m4qNyvV_Sf4.6AWTw&LSNPUBID=yNfEamYSgXk&utm_source=aff-campaign&utm_medium=udemyads\"\n", + "short_url = shorten_url(long_url)\n", + "print(\"Short URL:\", short_url)" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "2A7ZhezBPWfI", + "outputId": "985aeed1-47e3-42a0-d8c1-2fb4e2f1d35b" + }, + "execution_count": null, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Short URL: https://tinyurl.com/2pgefbna\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "import pyshorteners\n", + "\n", + "def shorten_url(url):\n", + " s = pyshorteners.Shortener()\n", + " shortened_url = s.tinyurl.short(url)\n", + " return shortened_url\n", + "\n", + "# Example usage\n", + "long_url = \"https://www.udemy.com/course/the-complete-web-development-bootcamp/\"\n", + "short_url = shorten_url(long_url)\n", + "print(\"Short URL:\", short_url)" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "3t0NPFBaPcxX", + "outputId": "36af6c88-062d-4304-a3dc-a29e05049d51" + }, + "execution_count": null, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Short URL: https://tinyurl.com/y9fhfkju\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "import pyshorteners\n", + "\n", + "def shorten_url(url):\n", + " s = pyshorteners.Shortener()\n", + " shortened_url = s.tinyurl.short(url)\n", + " return shortened_url\n", + "\n", + "# Example usage\n", + "long_url = \"https://www.udemy.com/course/100-days-of-code/\"\n", + "short_url = shorten_url(long_url)\n", + "print(\"Short URL:\", short_url)" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "sZMul52QP1yP", + "outputId": "304362de-3df7-4f21-912d-00cc4d2d5e10" + }, + "execution_count": null, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Short URL: https://tinyurl.com/y23h4x9l\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "import pyshorteners\n", + "\n", + "def shorten_url(url):\n", + " s = pyshorteners.Shortener()\n", + " shortened_url = s.tinyurl.short(url)\n", + " return shortened_url\n", + "\n", + "# Example usage\n", + "long_url = \"https://www.udemy.com/course/aws-certified-cloud-practitioner-new/\"\n", + "short_url = shorten_url(long_url)\n", + "print(\"Short URL:\", short_url)" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "IWSamMgKP9bt", + "outputId": "cfe11c31-a844-4868-e563-5bae26f17497" + }, + "execution_count": null, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Short URL: https://tinyurl.com/yd8k7zmw\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "import pyshorteners\n", + "\n", + "def shorten_url(url):\n", + " s = pyshorteners.Shortener()\n", + " shortened_url = s.tinyurl.short(url)\n", + " return shortened_url\n", + "\n", + "# Example usage\n", + "long_url = \"https://www.udemy.com/course/aws-certified-solutions-architect-associate-saa-c03/\"\n", + "short_url = shorten_url(long_url)\n", + "print(\"Short URL:\", short_url)" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "hSR0CGjUQEGu", + "outputId": "c64b3109-143b-46c2-f3b5-d54723b02faa" + }, + "execution_count": null, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Short URL: https://tinyurl.com/2o7km274\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "import pyshorteners\n", + "\n", + "def shorten_url(url):\n", + " s = pyshorteners.Shortener()\n", + " shortened_url = s.tinyurl.short(url)\n", + " return shortened_url\n", + "\n", + "# Example usage\n", + "long_url = \"https://www.udemy.com/course/react-the-complete-guide-incl-redux/\"\n", + "short_url = shorten_url(long_url)\n", + "print(\"Short URL:\", short_url)" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "lGEkCwUBQL54", + "outputId": "320dd29d-9004-4452-ef2f-927707255055" + }, + "execution_count": null, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Short URL: https://tinyurl.com/u5yxn5u\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "from collections import defaultdict\n", + "\n", + "class ShortenerMetricsAPI:\n", + " def __init__(self):\n", + " self.shortened_links = defaultdict(int)\n", + " \n", + " def add_shortened_link(self, url):\n", + " domain = self.get_domain(url)\n", + " self.shortened_links[domain] += 1\n", + " \n", + " def get_domain(self, url):\n", + " # extract the domain from the URL\n", + " return url.split(\"//\")[-1].split(\"/\")[0].split(\"?\")[0].split(\"#\")[0]\n", + " \n", + " def get_top_domains(self, n=3):\n", + " # sort the domains by the number of times they have been shortened\n", + " sorted_domains = sorted(self.shortened_links.items(), key=lambda x: x[1], reverse=True)\n", + " # return the top n domains\n", + " return sorted_domains[:n]\n" + ], + "metadata": { + "id": "9FDajndyNPpH" + }, + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "metrics_api = ShortenerMetricsAPI()\n", + "metrics_api.add_shortened_link(\"https://www.youtube.com/watch?v=E6GPMTDx41Y\")\n", + "metrics_api.add_shortened_link(\"https://www.youtube.com/watch?v=U8_YEWuBybI\")\n", + "metrics_api.add_shortened_link(\"https://www.youtube.com/watch?v=ZSiXZxVpVhs\")\n", + "metrics_api.add_shortened_link(\"https://www.youtube.com/watch?v=vYCjjAz3UD0\")\n", + "metrics_api.add_shortened_link(\"https://stackoverflow.blog/2021/12/30/how-often-do-people-actually-copy-and-paste-from-stack-overflow-now-we-know/\")\n", + "metrics_api.add_shortened_link(\"https://en.wikipedia.org/wiki/Artificial_Intelligence_Markup_Language\")\n", + "metrics_api.add_shortened_link(\"https://en.wikipedia.org/wiki/Artificial_Linguistic_Internet_Computer_Entity\")\n", + "metrics_api.add_shortened_link(\"https://www.udemy.com/?ranMID=39197&ranEAID=yNfEamYSgXk&ranSiteID=yNfEamYSgXk-FaJv9m4qNyvV_Sf4.6AWTw&LSNPUBID=yNfEamYSgXk&utm_source=aff-campaign&utm_medium=udemyads\")\n", + "metrics_api.add_shortened_link(\"https://www.udemy.com/course/the-complete-web-development-bootcamp/\")\n", + "metrics_api.add_shortened_link(\"https://www.udemy.com/course/100-days-of-code/\")\n", + "metrics_api.add_shortened_link(\"https://www.udemy.com/course/aws-certified-cloud-practitioner-new/\")\n", + "metrics_api.add_shortened_link(\"https://www.udemy.com/course/aws-certified-solutions-architect-associate-saa-c03/\")\n", + "metrics_api.add_shortened_link(\"https://www.udemy.com/course/react-the-complete-guide-incl-redux/\")\n", + "\n", + "top_domains = metrics_api.get_top_domains()\n", + "for domain, count in top_domains:\n", + " print(f\"{domain}: {count}\")" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "MOO0koj2bUzR", + "outputId": "24632f0a-8872-46ba-f01e-9e9889f2b57a" + }, + "execution_count": null, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "www.udemy.com: 6\n", + "www.youtube.com: 4\n", + "en.wikipedia.org: 2\n" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/Mudasarinfracloud.ipynb b/Mudasarinfracloud.ipynb new file mode 100644 index 0000000000..5e7e0ca4fc --- /dev/null +++ b/Mudasarinfracloud.ipynb @@ -0,0 +1,568 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "provenance": [], + "authorship_tag": "ABX9TyNvBXHoZW71MHcuumzXAp+z", + "include_colab_link": true + }, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + }, + "language_info": { + "name": "python" + } + }, + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "view-in-github", + "colab_type": "text" + }, + "source": [ + "\"Open" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "65lHeRTBMCBt", + "outputId": "920c903f-2c58-4784-b253-d8f15ec5310c" + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/\n", + "Collecting pyshorteners\n", + " Downloading pyshorteners-1.0.1.tar.gz (10.0 kB)\n", + " Preparing metadata (setup.py) ... \u001b[?25l\u001b[?25hdone\n", + "Requirement already satisfied: requests in /usr/local/lib/python3.10/dist-packages (from pyshorteners) (2.27.1)\n", + "Requirement already satisfied: urllib3<1.27,>=1.21.1 in /usr/local/lib/python3.10/dist-packages (from requests->pyshorteners) (1.26.15)\n", + "Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.10/dist-packages (from requests->pyshorteners) (2022.12.7)\n", + "Requirement already satisfied: charset-normalizer~=2.0.0 in /usr/local/lib/python3.10/dist-packages (from requests->pyshorteners) (2.0.12)\n", + "Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.10/dist-packages (from requests->pyshorteners) (3.4)\n", + "Building wheels for collected packages: pyshorteners\n", + " Building wheel for pyshorteners (setup.py) ... \u001b[?25l\u001b[?25hdone\n", + " Created wheel for pyshorteners: filename=pyshorteners-1.0.1-py3-none-any.whl size=17479 sha256=afe94b3bc7dc3f7e592db1b9208bf58a98b1e709af4ec395a2459e01b7ac994e\n", + " Stored in directory: /root/.cache/pip/wheels/d5/ff/b3/16d8906f92ab0b042f76a4696fcea11d291d79a2b3a3de1e78\n", + "Successfully built pyshorteners\n", + "Installing collected packages: pyshorteners\n", + "Successfully installed pyshorteners-1.0.1\n" + ] + } + ], + "source": [ + "pip install pyshorteners" + ] + }, + { + "cell_type": "code", + "source": [ + "import pyshorteners\n", + "\n", + "def shorten_url(url):\n", + " s = pyshorteners.Shortener()\n", + " shortened_url = s.tinyurl.short(url)\n", + " return shortened_url\n", + "\n", + "# Example usage\n", + "long_url = \"https://www.youtube.com/watch?v=E6GPMTDx41Y\"\n", + "short_url = shorten_url(long_url)\n", + "print(\"Short URL:\", short_url)" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "e3Pg6XaLMfAg", + "outputId": "a185e7c9-524a-4285-a59b-efae85ce732e" + }, + "execution_count": null, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Short URL: https://tinyurl.com/2g47dx37\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "import pyshorteners\n", + "\n", + "def shorten_url(url):\n", + " s = pyshorteners.Shortener()\n", + " shortened_url = s.tinyurl.short(url)\n", + " return shortened_url\n", + "\n", + "# Example usage\n", + "long_url = \"https://www.youtube.com/watch?v=U8_YEWuBybI\"\n", + "short_url = shorten_url(long_url)\n", + "print(\"Short URL:\", short_url)" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "-_cshk2dNq-r", + "outputId": "3f3f429f-27a6-44b2-fcfb-a2a7ffa2ab75" + }, + "execution_count": null, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Short URL: https://tinyurl.com/2h4vcxuk\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "import pyshorteners\n", + "\n", + "def shorten_url(url):\n", + " s = pyshorteners.Shortener()\n", + " shortened_url = s.tinyurl.short(url)\n", + " return shortened_url\n", + "\n", + "# Example usage\n", + "long_url = \"https://www.youtube.com/watch?v=ZSiXZxVpVhs\"\n", + "short_url = shorten_url(long_url)\n", + "print(\"Short URL:\", short_url)" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "dHNc7GWMOi2S", + "outputId": "81e8f8f2-1445-43e7-d510-245c2131a0fd" + }, + "execution_count": null, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Short URL: https://tinyurl.com/2r2pcw4c\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "import pyshorteners\n", + "\n", + "def shorten_url(url):\n", + " s = pyshorteners.Shortener()\n", + " shortened_url = s.tinyurl.short(url)\n", + " return shortened_url\n", + "\n", + "# Example usage\n", + "long_url = \"https://www.youtube.com/watch?v=vYCjjAz3UD0\"\n", + "short_url = shorten_url(long_url)\n", + "print(\"Short URL:\", short_url)" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "gbEFz6OCOvZO", + "outputId": "180287e0-fc17-4e7d-90c3-60b9bf4a9385" + }, + "execution_count": null, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Short URL: https://tinyurl.com/2fzbn924\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "import pyshorteners\n", + "\n", + "def shorten_url(url):\n", + " s = pyshorteners.Shortener()\n", + " shortened_url = s.tinyurl.short(url)\n", + " return shortened_url\n", + "\n", + "# Example usage\n", + "long_url = \"https://stackoverflow.blog/2021/12/30/how-often-do-people-actually-copy-and-paste-from-stack-overflow-now-we-know/\"\n", + "short_url = shorten_url(long_url)\n", + "print(\"Short URL:\", short_url)" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "YfHDQiwHO8Ob", + "outputId": "23074cb2-6e2d-4b89-bbef-a2e5a0d06dd9" + }, + "execution_count": null, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Short URL: https://tinyurl.com/2knnnyae\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "import pyshorteners\n", + "\n", + "def shorten_url(url):\n", + " s = pyshorteners.Shortener()\n", + " shortened_url = s.tinyurl.short(url)\n", + " return shortened_url\n", + "\n", + "# Example usage\n", + "long_url = \"https://en.wikipedia.org/wiki/Artificial_Intelligence_Markup_Language\"\n", + "short_url = shorten_url(long_url)\n", + "print(\"Short URL:\", short_url)" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "I9Z3VsP6PFFw", + "outputId": "cc574317-ed7c-4b6b-a402-722b2bba801f" + }, + "execution_count": null, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Short URL: https://tinyurl.com/2occ6bkt\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "import pyshorteners\n", + "\n", + "def shorten_url(url):\n", + " s = pyshorteners.Shortener()\n", + " shortened_url = s.tinyurl.short(url)\n", + " return shortened_url\n", + "\n", + "# Example usage\n", + "long_url = \"https://en.wikipedia.org/wiki/Artificial_Linguistic_Internet_Computer_Entity\"\n", + "short_url = shorten_url(long_url)\n", + "print(\"Short URL:\", short_url)" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "OKIstCCnPNqz", + "outputId": "e9348b71-6ec0-45b4-efd8-e4e7deb6e78e" + }, + "execution_count": null, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Short URL: https://tinyurl.com/cdgsybc\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "import pyshorteners\n", + "\n", + "def shorten_url(url):\n", + " s = pyshorteners.Shortener()\n", + " shortened_url = s.tinyurl.short(url)\n", + " return shortened_url\n", + "\n", + "# Example usage\n", + "long_url = \"https://www.udemy.com/?ranMID=39197&ranEAID=yNfEamYSgXk&ranSiteID=yNfEamYSgXk-FaJv9m4qNyvV_Sf4.6AWTw&LSNPUBID=yNfEamYSgXk&utm_source=aff-campaign&utm_medium=udemyads\"\n", + "short_url = shorten_url(long_url)\n", + "print(\"Short URL:\", short_url)" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "2A7ZhezBPWfI", + "outputId": "985aeed1-47e3-42a0-d8c1-2fb4e2f1d35b" + }, + "execution_count": null, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Short URL: https://tinyurl.com/2pgefbna\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "import pyshorteners\n", + "\n", + "def shorten_url(url):\n", + " s = pyshorteners.Shortener()\n", + " shortened_url = s.tinyurl.short(url)\n", + " return shortened_url\n", + "\n", + "# Example usage\n", + "long_url = \"https://www.udemy.com/course/the-complete-web-development-bootcamp/\"\n", + "short_url = shorten_url(long_url)\n", + "print(\"Short URL:\", short_url)" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "3t0NPFBaPcxX", + "outputId": "36af6c88-062d-4304-a3dc-a29e05049d51" + }, + "execution_count": null, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Short URL: https://tinyurl.com/y9fhfkju\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "import pyshorteners\n", + "\n", + "def shorten_url(url):\n", + " s = pyshorteners.Shortener()\n", + " shortened_url = s.tinyurl.short(url)\n", + " return shortened_url\n", + "\n", + "# Example usage\n", + "long_url = \"https://www.udemy.com/course/100-days-of-code/\"\n", + "short_url = shorten_url(long_url)\n", + "print(\"Short URL:\", short_url)" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "sZMul52QP1yP", + "outputId": "304362de-3df7-4f21-912d-00cc4d2d5e10" + }, + "execution_count": null, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Short URL: https://tinyurl.com/y23h4x9l\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "import pyshorteners\n", + "\n", + "def shorten_url(url):\n", + " s = pyshorteners.Shortener()\n", + " shortened_url = s.tinyurl.short(url)\n", + " return shortened_url\n", + "\n", + "# Example usage\n", + "long_url = \"https://www.udemy.com/course/aws-certified-cloud-practitioner-new/\"\n", + "short_url = shorten_url(long_url)\n", + "print(\"Short URL:\", short_url)" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "IWSamMgKP9bt", + "outputId": "cfe11c31-a844-4868-e563-5bae26f17497" + }, + "execution_count": null, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Short URL: https://tinyurl.com/yd8k7zmw\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "import pyshorteners\n", + "\n", + "def shorten_url(url):\n", + " s = pyshorteners.Shortener()\n", + " shortened_url = s.tinyurl.short(url)\n", + " return shortened_url\n", + "\n", + "# Example usage\n", + "long_url = \"https://www.udemy.com/course/aws-certified-solutions-architect-associate-saa-c03/\"\n", + "short_url = shorten_url(long_url)\n", + "print(\"Short URL:\", short_url)" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "hSR0CGjUQEGu", + "outputId": "c64b3109-143b-46c2-f3b5-d54723b02faa" + }, + "execution_count": null, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Short URL: https://tinyurl.com/2o7km274\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "import pyshorteners\n", + "\n", + "def shorten_url(url):\n", + " s = pyshorteners.Shortener()\n", + " shortened_url = s.tinyurl.short(url)\n", + " return shortened_url\n", + "\n", + "# Example usage\n", + "long_url = \"https://www.udemy.com/course/react-the-complete-guide-incl-redux/\"\n", + "short_url = shorten_url(long_url)\n", + "print(\"Short URL:\", short_url)" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "lGEkCwUBQL54", + "outputId": "320dd29d-9004-4452-ef2f-927707255055" + }, + "execution_count": null, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Short URL: https://tinyurl.com/u5yxn5u\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "from collections import defaultdict\n", + "\n", + "class ShortenerMetricsAPI:\n", + " def __init__(self):\n", + " self.shortened_links = defaultdict(int)\n", + " \n", + " def add_shortened_link(self, url):\n", + " domain = self.get_domain(url)\n", + " self.shortened_links[domain] += 1\n", + " \n", + " def get_domain(self, url):\n", + " # extract the domain from the URL\n", + " return url.split(\"//\")[-1].split(\"/\")[0].split(\"?\")[0].split(\"#\")[0]\n", + " \n", + " def get_top_domains(self, n=3):\n", + " # sort the domains by the number of times they have been shortened\n", + " sorted_domains = sorted(self.shortened_links.items(), key=lambda x: x[1], reverse=True)\n", + " # return the top n domains\n", + " return sorted_domains[:n]\n" + ], + "metadata": { + "id": "9FDajndyNPpH" + }, + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "metrics_api = ShortenerMetricsAPI()\n", + "metrics_api.add_shortened_link(\"https://www.youtube.com/watch?v=E6GPMTDx41Y\")\n", + "metrics_api.add_shortened_link(\"https://www.youtube.com/watch?v=U8_YEWuBybI\")\n", + "metrics_api.add_shortened_link(\"https://www.youtube.com/watch?v=ZSiXZxVpVhs\")\n", + "metrics_api.add_shortened_link(\"https://www.youtube.com/watch?v=vYCjjAz3UD0\")\n", + "metrics_api.add_shortened_link(\"https://stackoverflow.blog/2021/12/30/how-often-do-people-actually-copy-and-paste-from-stack-overflow-now-we-know/\")\n", + "metrics_api.add_shortened_link(\"https://en.wikipedia.org/wiki/Artificial_Intelligence_Markup_Language\")\n", + "metrics_api.add_shortened_link(\"https://en.wikipedia.org/wiki/Artificial_Linguistic_Internet_Computer_Entity\")\n", + "metrics_api.add_shortened_link(\"https://www.udemy.com/?ranMID=39197&ranEAID=yNfEamYSgXk&ranSiteID=yNfEamYSgXk-FaJv9m4qNyvV_Sf4.6AWTw&LSNPUBID=yNfEamYSgXk&utm_source=aff-campaign&utm_medium=udemyads\")\n", + "metrics_api.add_shortened_link(\"https://www.udemy.com/course/the-complete-web-development-bootcamp/\")\n", + "metrics_api.add_shortened_link(\"https://www.udemy.com/course/100-days-of-code/\")\n", + "metrics_api.add_shortened_link(\"https://www.udemy.com/course/aws-certified-cloud-practitioner-new/\")\n", + "metrics_api.add_shortened_link(\"https://www.udemy.com/course/aws-certified-solutions-architect-associate-saa-c03/\")\n", + "metrics_api.add_shortened_link(\"https://www.udemy.com/course/react-the-complete-guide-incl-redux/\")\n", + "\n", + "top_domains = metrics_api.get_top_domains()\n", + "for domain, count in top_domains:\n", + " print(f\"{domain}: {count}\")" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "MOO0koj2bUzR", + "outputId": "24632f0a-8872-46ba-f01e-9e9889f2b57a" + }, + "execution_count": null, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "www.udemy.com: 6\n", + "www.youtube.com: 4\n", + "en.wikipedia.org: 2\n" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/Mudasarinfracloudupdated.ipynb b/Mudasarinfracloudupdated.ipynb new file mode 100644 index 0000000000..4d5792f0be --- /dev/null +++ b/Mudasarinfracloudupdated.ipynb @@ -0,0 +1,568 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "provenance": [], + "authorship_tag": "ABX9TyNvBXHoZW71MHcuumzXAp+z", + "include_colab_link": true + }, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + }, + "language_info": { + "name": "python" + } + }, + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "view-in-github", + "colab_type": "text" + }, + "source": [ + "\"Open" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "65lHeRTBMCBt", + "outputId": "920c903f-2c58-4784-b253-d8f15ec5310c" + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/\n", + "Collecting pyshorteners\n", + " Downloading pyshorteners-1.0.1.tar.gz (10.0 kB)\n", + " Preparing metadata (setup.py) ... \u001b[?25l\u001b[?25hdone\n", + "Requirement already satisfied: requests in /usr/local/lib/python3.10/dist-packages (from pyshorteners) (2.27.1)\n", + "Requirement already satisfied: urllib3<1.27,>=1.21.1 in /usr/local/lib/python3.10/dist-packages (from requests->pyshorteners) (1.26.15)\n", + "Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.10/dist-packages (from requests->pyshorteners) (2022.12.7)\n", + "Requirement already satisfied: charset-normalizer~=2.0.0 in /usr/local/lib/python3.10/dist-packages (from requests->pyshorteners) (2.0.12)\n", + "Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.10/dist-packages (from requests->pyshorteners) (3.4)\n", + "Building wheels for collected packages: pyshorteners\n", + " Building wheel for pyshorteners (setup.py) ... \u001b[?25l\u001b[?25hdone\n", + " Created wheel for pyshorteners: filename=pyshorteners-1.0.1-py3-none-any.whl size=17479 sha256=afe94b3bc7dc3f7e592db1b9208bf58a98b1e709af4ec395a2459e01b7ac994e\n", + " Stored in directory: /root/.cache/pip/wheels/d5/ff/b3/16d8906f92ab0b042f76a4696fcea11d291d79a2b3a3de1e78\n", + "Successfully built pyshorteners\n", + "Installing collected packages: pyshorteners\n", + "Successfully installed pyshorteners-1.0.1\n" + ] + } + ], + "source": [ + "pip install pyshorteners" + ] + }, + { + "cell_type": "code", + "source": [ + "import pyshorteners\n", + "\n", + "def shorten_url(url):\n", + " s = pyshorteners.Shortener()\n", + " shortened_url = s.tinyurl.short(url)\n", + " return shortened_url\n", + "\n", + "# Example usage\n", + "long_url = \"https://www.youtube.com/watch?v=E6GPMTDx41Y\"\n", + "short_url = shorten_url(long_url)\n", + "print(\"Short URL:\", short_url)" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "e3Pg6XaLMfAg", + "outputId": "a185e7c9-524a-4285-a59b-efae85ce732e" + }, + "execution_count": null, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Short URL: https://tinyurl.com/2g47dx37\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "import pyshorteners\n", + "\n", + "def shorten_url(url):\n", + " s = pyshorteners.Shortener()\n", + " shortened_url = s.tinyurl.short(url)\n", + " return shortened_url\n", + "\n", + "# Example usage\n", + "long_url = \"https://www.youtube.com/watch?v=U8_YEWuBybI\"\n", + "short_url = shorten_url(long_url)\n", + "print(\"Short URL:\", short_url)" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "-_cshk2dNq-r", + "outputId": "3f3f429f-27a6-44b2-fcfb-a2a7ffa2ab75" + }, + "execution_count": null, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Short URL: https://tinyurl.com/2h4vcxuk\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "import pyshorteners\n", + "\n", + "def shorten_url(url):\n", + " s = pyshorteners.Shortener()\n", + " shortened_url = s.tinyurl.short(url)\n", + " return shortened_url\n", + "\n", + "# Example usage\n", + "long_url = \"https://www.youtube.com/watch?v=ZSiXZxVpVhs\"\n", + "short_url = shorten_url(long_url)\n", + "print(\"Short URL:\", short_url)" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "dHNc7GWMOi2S", + "outputId": "81e8f8f2-1445-43e7-d510-245c2131a0fd" + }, + "execution_count": null, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Short URL: https://tinyurl.com/2r2pcw4c\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "import pyshorteners\n", + "\n", + "def shorten_url(url):\n", + " s = pyshorteners.Shortener()\n", + " shortened_url = s.tinyurl.short(url)\n", + " return shortened_url\n", + "\n", + "# Example usage\n", + "long_url = \"https://www.youtube.com/watch?v=vYCjjAz3UD0\"\n", + "short_url = shorten_url(long_url)\n", + "print(\"Short URL:\", short_url)" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "gbEFz6OCOvZO", + "outputId": "180287e0-fc17-4e7d-90c3-60b9bf4a9385" + }, + "execution_count": null, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Short URL: https://tinyurl.com/2fzbn924\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "import pyshorteners\n", + "\n", + "def shorten_url(url):\n", + " s = pyshorteners.Shortener()\n", + " shortened_url = s.tinyurl.short(url)\n", + " return shortened_url\n", + "\n", + "# Example usage\n", + "long_url = \"https://stackoverflow.blog/2021/12/30/how-often-do-people-actually-copy-and-paste-from-stack-overflow-now-we-know/\"\n", + "short_url = shorten_url(long_url)\n", + "print(\"Short URL:\", short_url)" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "YfHDQiwHO8Ob", + "outputId": "23074cb2-6e2d-4b89-bbef-a2e5a0d06dd9" + }, + "execution_count": null, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Short URL: https://tinyurl.com/2knnnyae\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "import pyshorteners\n", + "\n", + "def shorten_url(url):\n", + " s = pyshorteners.Shortener()\n", + " shortened_url = s.tinyurl.short(url)\n", + " return shortened_url\n", + "\n", + "# Example usage\n", + "long_url = \"https://en.wikipedia.org/wiki/Artificial_Intelligence_Markup_Language\"\n", + "short_url = shorten_url(long_url)\n", + "print(\"Short URL:\", short_url)" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "I9Z3VsP6PFFw", + "outputId": "cc574317-ed7c-4b6b-a402-722b2bba801f" + }, + "execution_count": null, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Short URL: https://tinyurl.com/2occ6bkt\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "import pyshorteners\n", + "\n", + "def shorten_url(url):\n", + " s = pyshorteners.Shortener()\n", + " shortened_url = s.tinyurl.short(url)\n", + " return shortened_url\n", + "\n", + "# Example usage\n", + "long_url = \"https://en.wikipedia.org/wiki/Artificial_Linguistic_Internet_Computer_Entity\"\n", + "short_url = shorten_url(long_url)\n", + "print(\"Short URL:\", short_url)" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "OKIstCCnPNqz", + "outputId": "e9348b71-6ec0-45b4-efd8-e4e7deb6e78e" + }, + "execution_count": null, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Short URL: https://tinyurl.com/cdgsybc\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "import pyshorteners\n", + "\n", + "def shorten_url(url):\n", + " s = pyshorteners.Shortener()\n", + " shortened_url = s.tinyurl.short(url)\n", + " return shortened_url\n", + "\n", + "# Example usage\n", + "long_url = \"https://www.udemy.com/?ranMID=39197&ranEAID=yNfEamYSgXk&ranSiteID=yNfEamYSgXk-FaJv9m4qNyvV_Sf4.6AWTw&LSNPUBID=yNfEamYSgXk&utm_source=aff-campaign&utm_medium=udemyads\"\n", + "short_url = shorten_url(long_url)\n", + "print(\"Short URL:\", short_url)" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "2A7ZhezBPWfI", + "outputId": "985aeed1-47e3-42a0-d8c1-2fb4e2f1d35b" + }, + "execution_count": null, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Short URL: https://tinyurl.com/2pgefbna\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "import pyshorteners\n", + "\n", + "def shorten_url(url):\n", + " s = pyshorteners.Shortener()\n", + " shortened_url = s.tinyurl.short(url)\n", + " return shortened_url\n", + "\n", + "# Example usage\n", + "long_url = \"https://www.udemy.com/course/the-complete-web-development-bootcamp/\"\n", + "short_url = shorten_url(long_url)\n", + "print(\"Short URL:\", short_url)" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "3t0NPFBaPcxX", + "outputId": "36af6c88-062d-4304-a3dc-a29e05049d51" + }, + "execution_count": null, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Short URL: https://tinyurl.com/y9fhfkju\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "import pyshorteners\n", + "\n", + "def shorten_url(url):\n", + " s = pyshorteners.Shortener()\n", + " shortened_url = s.tinyurl.short(url)\n", + " return shortened_url\n", + "\n", + "# Example usage\n", + "long_url = \"https://www.udemy.com/course/100-days-of-code/\"\n", + "short_url = shorten_url(long_url)\n", + "print(\"Short URL:\", short_url)" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "sZMul52QP1yP", + "outputId": "304362de-3df7-4f21-912d-00cc4d2d5e10" + }, + "execution_count": null, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Short URL: https://tinyurl.com/y23h4x9l\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "import pyshorteners\n", + "\n", + "def shorten_url(url):\n", + " s = pyshorteners.Shortener()\n", + " shortened_url = s.tinyurl.short(url)\n", + " return shortened_url\n", + "\n", + "# Example usage\n", + "long_url = \"https://www.udemy.com/course/aws-certified-cloud-practitioner-new/\"\n", + "short_url = shorten_url(long_url)\n", + "print(\"Short URL:\", short_url)" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "IWSamMgKP9bt", + "outputId": "cfe11c31-a844-4868-e563-5bae26f17497" + }, + "execution_count": null, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Short URL: https://tinyurl.com/yd8k7zmw\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "import pyshorteners\n", + "\n", + "def shorten_url(url):\n", + " s = pyshorteners.Shortener()\n", + " shortened_url = s.tinyurl.short(url)\n", + " return shortened_url\n", + "\n", + "# Example usage\n", + "long_url = \"https://www.udemy.com/course/aws-certified-solutions-architect-associate-saa-c03/\"\n", + "short_url = shorten_url(long_url)\n", + "print(\"Short URL:\", short_url)" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "hSR0CGjUQEGu", + "outputId": "c64b3109-143b-46c2-f3b5-d54723b02faa" + }, + "execution_count": null, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Short URL: https://tinyurl.com/2o7km274\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "import pyshorteners\n", + "\n", + "def shorten_url(url):\n", + " s = pyshorteners.Shortener()\n", + " shortened_url = s.tinyurl.short(url)\n", + " return shortened_url\n", + "\n", + "# Example usage\n", + "long_url = \"https://www.udemy.com/course/react-the-complete-guide-incl-redux/\"\n", + "short_url = shorten_url(long_url)\n", + "print(\"Short URL:\", short_url)" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "lGEkCwUBQL54", + "outputId": "320dd29d-9004-4452-ef2f-927707255055" + }, + "execution_count": null, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Short URL: https://tinyurl.com/u5yxn5u\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "from collections import defaultdict\n", + "\n", + "class ShortenerMetricsAPI:\n", + " def __init__(self):\n", + " self.shortened_links = defaultdict(int)\n", + " \n", + " def add_shortened_link(self, url):\n", + " domain = self.get_domain(url)\n", + " self.shortened_links[domain] += 1\n", + " \n", + " def get_domain(self, url):\n", + " # extract the domain from the URL\n", + " return url.split(\"//\")[-1].split(\"/\")[0].split(\"?\")[0].split(\"#\")[0]\n", + " \n", + " def get_top_domains(self, n=3):\n", + " # sort the domains by the number of times they have been shortened\n", + " sorted_domains = sorted(self.shortened_links.items(), key=lambda x: x[1], reverse=True)\n", + " # return the top n domains\n", + " return sorted_domains[:n]\n" + ], + "metadata": { + "id": "9FDajndyNPpH" + }, + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "metrics_api = ShortenerMetricsAPI()\n", + "metrics_api.add_shortened_link(\"https://www.youtube.com/watch?v=E6GPMTDx41Y\")\n", + "metrics_api.add_shortened_link(\"https://www.youtube.com/watch?v=U8_YEWuBybI\")\n", + "metrics_api.add_shortened_link(\"https://www.youtube.com/watch?v=ZSiXZxVpVhs\")\n", + "metrics_api.add_shortened_link(\"https://www.youtube.com/watch?v=vYCjjAz3UD0\")\n", + "metrics_api.add_shortened_link(\"https://stackoverflow.blog/2021/12/30/how-often-do-people-actually-copy-and-paste-from-stack-overflow-now-we-know/\")\n", + "metrics_api.add_shortened_link(\"https://en.wikipedia.org/wiki/Artificial_Intelligence_Markup_Language\")\n", + "metrics_api.add_shortened_link(\"https://en.wikipedia.org/wiki/Artificial_Linguistic_Internet_Computer_Entity\")\n", + "metrics_api.add_shortened_link(\"https://www.udemy.com/?ranMID=39197&ranEAID=yNfEamYSgXk&ranSiteID=yNfEamYSgXk-FaJv9m4qNyvV_Sf4.6AWTw&LSNPUBID=yNfEamYSgXk&utm_source=aff-campaign&utm_medium=udemyads\")\n", + "metrics_api.add_shortened_link(\"https://www.udemy.com/course/the-complete-web-development-bootcamp/\")\n", + "metrics_api.add_shortened_link(\"https://www.udemy.com/course/100-days-of-code/\")\n", + "metrics_api.add_shortened_link(\"https://www.udemy.com/course/aws-certified-cloud-practitioner-new/\")\n", + "metrics_api.add_shortened_link(\"https://www.udemy.com/course/aws-certified-solutions-architect-associate-saa-c03/\")\n", + "metrics_api.add_shortened_link(\"https://www.udemy.com/course/react-the-complete-guide-incl-redux/\")\n", + "\n", + "top_domains = metrics_api.get_top_domains()\n", + "for domain, count in top_domains:\n", + " print(f\"{domain}: {count}\")" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "MOO0koj2bUzR", + "outputId": "24632f0a-8872-46ba-f01e-9e9889f2b57a" + }, + "execution_count": null, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "www.udemy.com: 6\n", + "www.youtube.com: 4\n", + "en.wikipedia.org: 2\n" + ] + } + ] + } + ] +} \ No newline at end of file