This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime | |
import dataclasses | |
import pygsheets | |
import json | |
import time | |
from playwright.sync_api import sync_playwright | |
import re | |
import pywhatkit | |
import pyautogui | |
import keyboard |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import logging | |
import os | |
import subprocess | |
import sys | |
import time | |
import urllib | |
from logging import getLogger | |
from dotenv import load_dotenv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import logging | |
import os | |
import subprocess | |
import sys | |
import time | |
import urllib | |
from logging import getLogger | |
from dotenv import load_dotenv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from turtle import * | |
import turtle as tur | |
t = tur.Turtle() | |
tur.speed(6) | |
tur.bgcolor("black") | |
tur.color("gold") | |
tur.pensize(5) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask, request, Response, jsonify | |
from flask_sqlalchemy import SQLAlchemy | |
app = Flask(__name__) | |
db = SQLAlchemy(app) | |
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///database.db' | |
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False | |
class Todo(db.Model): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from email import header | |
from aiohttp import web | |
import sqlite3 | |
import validators | |
import requests | |
import requests.exceptions | |
from http import HTTPStatus | |
import json | |
import string | |
import random |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@routes.get("/{code}") | |
async def redirect_to_longurl(request): | |
"""Function to retrieve long URL based on code | |
:param request: HTTP request | |
""" | |
data = request.match_info["code"] | |
longurl = cursor.execute("SELECT longurl from URLSHORTNER where code = ?",(data,)).fetchone() | |
print(longurl[0]) | |
return web.HTTPFound(longurl[0]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def validate_url_format(longurl: str): | |
"""This function returns True if the longurl is in a valid format""" | |
return validators.url(longurl) | |
def validate_url(longurl: str): | |
"""This function returns True if the longurl is a valid web address""" | |
try: | |
headers = {'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:80.0) Gecko/20100101 Firefox/80.0'} | |
response = requests.get(longurl, headers=headers) | |
return response.status_code == HTTPStatus.OK |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sqlite3 | |
from aiohttp import web | |
# create a sqllite db | |
connection = sqlite3.connect("urlshortner.db") | |
cursor = connection.cursor() | |
routes = web.RouteTableDef() | |
if __name__ == "__main__": |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
NewerOlder