Skip to content

Instantly share code, notes, and snippets.

View jaydeepkarale's full-sized avatar

Jaydeep Karale jaydeepkarale

View GitHub Profile
@jaydeepkarale
jaydeepkarale / shortening.py
Created June 23, 2022 12:40
Ngrok & Shortening
import random
import json
import string
# get the ngrok tunnel url
def get_ngrok_url():
"""Function to get ngrok url"""
url = "http://localhost:4040/api/tunnels"
res = requests.get(url)
res_unicode = res.content.decode("utf-8")
@jaydeepkarale
jaydeepkarale / validateurls.py
Last active June 24, 2022 16:25
Validate URL Snippets
from aiohttp import web
from http import HTTPStatus
import validators
import requests
def validate_url_format(longurl: str):
"""This function returns True if the longurl is in a valid format"""
return validators.url(longurl)
@jaydeepkarale
jaydeepkarale / aiohttpinit.py
Last active June 23, 2022 12:54
AIOHTTP Server In Python
"""Main file for performing url shortening"""
from aiohttp import web
# instead of adding routes one by one we use the RouteTtableDef which will auto collect all @route annotations
routes = web.RouteTableDef()
# this will create a route 127.0.0.1:8000/shorten
@routes.get("/shorten")
async def shorten(request):
"""Function to accept HTTP request with long url & call shortening logic